1 var http = require('http');
2 var https = require('https');
4 var express = require('express');
5 const stream = require('stream');
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};
13 var bodyParser = require('body-parser')
15 // parse application/x-www-form-urlencoded
16 app.use(bodyParser.urlencoded({ extended: false }))
18 // parse application/json
19 app.use(bodyParser.json())
21 // parse application/vnd.api+json as json
22 app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
24 // parse some custom thing into a Buffer
25 app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' }))
27 // parse an HTML body into a string
28 app.use(bodyParser.text({ type: 'text/html' }))
29 app.get("/",function(req, res){
33 app.put('/publish/1/:filename', function (req, res) {
34 console.log(req.files);
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); }
45 var httpServer = http.createServer(app);
46 var httpsServer = https.createServer(credentials, app);
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)