TamasBakai | 9b78033 | 2019-02-15 08:38:16 +0000 | [diff] [blame^] | 1 | var http = require('http'); |
| 2 | var https = require('https'); |
| 3 | |
| 4 | var express = require('express'); |
| 5 | const stream = require('stream'); |
| 6 | var app = express(); |
| 7 | var fs = require("fs"); |
| 8 | var path = require('path'); |
| 9 | var privateKey = fs.readFileSync('cert/private.key', 'utf8'); |
| 10 | var certificate = fs.readFileSync('cert/certificate.crt', 'utf8'); |
| 11 | var credentials = {key: privateKey, cert: certificate}; |
| 12 | |
| 13 | var bodyParser = require('body-parser') |
| 14 | |
| 15 | // parse application/x-www-form-urlencoded |
| 16 | app.use(bodyParser.urlencoded({ extended: false })) |
| 17 | |
| 18 | // parse application/json |
| 19 | app.use(bodyParser.json()) |
| 20 | |
| 21 | // parse application/vnd.api+json as json |
| 22 | app.use(bodyParser.json({ type: 'application/vnd.api+json' })) |
| 23 | |
| 24 | // parse some custom thing into a Buffer |
| 25 | app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' })) |
| 26 | |
| 27 | // parse an HTML body into a string |
| 28 | app.use(bodyParser.text({ type: 'text/html' })) |
| 29 | app.get("/",function(req, res){ |
| 30 | res.send("ok"); |
| 31 | }) |
| 32 | |
| 33 | app.put('/publish/1/:filename', function (req, res) { |
| 34 | console.log(req.files); |
| 35 | console.log(req.body) |
| 36 | console.log(req.headers) |
| 37 | var filename = path.basename(req.params.filename); |
| 38 | filename = path.resolve(__dirname, filename); |
| 39 | console.log(req.params.filename); |
| 40 | fs.writeFile(filename, req.body, function (error) { |
| 41 | if (error) { console.error(error); } |
| 42 | }); |
| 43 | res.send("ok") |
| 44 | }) |
| 45 | var httpServer = http.createServer(app); |
| 46 | var httpsServer = https.createServer(credentials, app); |
| 47 | |
| 48 | var httpPort=3908 |
| 49 | var httpsPort=3909 |
| 50 | httpServer.listen(httpPort); |
| 51 | console.log("DR-simulator listening (http) at "+httpPort) |
| 52 | httpsServer.listen(httpsPort); |
| 53 | console.log("DR-simulator listening (https) at "+httpsPort) |
| 54 | |