blob: 5be1f689e4d0195fb540c59aa786de3c3905c320 [file] [log] [blame]
TamasBakai9b780332019-02-15 08:38:16 +00001var http = require('http');
2var https = require('https');
3
4var express = require('express');
5const stream = require('stream');
6var app = express();
7var fs = require("fs");
8var path = require('path');
9var privateKey = fs.readFileSync('cert/private.key', 'utf8');
10var certificate = fs.readFileSync('cert/certificate.crt', 'utf8');
11var credentials = {key: privateKey, cert: certificate};
12
13var bodyParser = require('body-parser')
14
15// parse application/x-www-form-urlencoded
16app.use(bodyParser.urlencoded({ extended: false }))
17
18// parse application/json
19app.use(bodyParser.json())
20
21// parse application/vnd.api+json as json
22app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
23
24// parse some custom thing into a Buffer
25app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' }))
26
27// parse an HTML body into a string
28app.use(bodyParser.text({ type: 'text/html' }))
29app.get("/",function(req, res){
30 res.send("ok");
31})
32
33app.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})
45var httpServer = http.createServer(app);
46var httpsServer = https.createServer(credentials, app);
47
48var httpPort=3908
49var httpsPort=3909
50httpServer.listen(httpPort);
51console.log("DR-simulator listening (http) at "+httpPort)
52httpsServer.listen(httpsPort);
53console.log("DR-simulator listening (https) at "+httpsPort)
54