diff options
author | 2019-02-15 08:38:16 +0000 | |
---|---|---|
committer | 2019-02-15 09:47:28 +0000 | |
commit | 9b780338eb8b85fc713f272a7cae865f1265f109 (patch) | |
tree | 864c1ba60eff8625f1f5c79567da0914e5e8ed65 /test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js | |
parent | 01c69ab28550d775239697067588e3b2063188a1 (diff) |
Simulator scripts for datafile-collector
Change-Id: Idff5fb9e4406f42208367860b3d02fc2ed4a9bad
Issue-ID: DCAEGEN2-1225
Signed-off-by: TamasBakai <tamas.bakai@est.tech>
Diffstat (limited to 'test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js')
-rw-r--r-- | test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js new file mode 100644 index 000000000..5be1f689e --- /dev/null +++ b/test/mocks/datafilecollector-testharness/dr-sim/dmaapDR_redir.js @@ -0,0 +1,54 @@ +var http = require('http'); +var https = require('https'); + +var express = require('express'); +const stream = require('stream'); +var app = express(); +var fs = require("fs"); +var path = require('path'); +var privateKey = fs.readFileSync('cert/private.key', 'utf8'); +var certificate = fs.readFileSync('cert/certificate.crt', 'utf8'); +var credentials = {key: privateKey, cert: certificate}; + +var bodyParser = require('body-parser') + +// parse application/x-www-form-urlencoded +app.use(bodyParser.urlencoded({ extended: false })) + +// parse application/json +app.use(bodyParser.json()) + +// parse application/vnd.api+json as json +app.use(bodyParser.json({ type: 'application/vnd.api+json' })) + +// parse some custom thing into a Buffer +app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' })) + +// parse an HTML body into a string +app.use(bodyParser.text({ type: 'text/html' })) +app.get("/",function(req, res){ + res.send("ok"); +}) + +app.put('/publish/1/:filename', function (req, res) { + console.log(req.files); + console.log(req.body) + console.log(req.headers) + var filename = path.basename(req.params.filename); + filename = path.resolve(__dirname, filename); + console.log(req.params.filename); + fs.writeFile(filename, req.body, function (error) { + if (error) { console.error(error); } + }); + res.send("ok") +}) +var httpServer = http.createServer(app); +var httpsServer = https.createServer(credentials, app); + +var httpPort=3908 +var httpsPort=3909 +httpServer.listen(httpPort); +console.log("DR-simulator listening (http) at "+httpPort) +httpsServer.listen(httpsPort); +console.log("DR-simulator listening (https) at "+httpsPort) + |