blob: 7e57b6151303affd8fbabef0c4bc46ca06520282 [file] [log] [blame]
TamasBakai9b780332019-02-15 08:38:16 +00001var http = require('http');
2var https = require('https');
3var ArgumentParser = require('argparse').ArgumentParser;
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
13
14var parser = new ArgumentParser({
15 version: '0.0.1',
16 addHelp:true,
17 description: 'Datarouter simulator'
18 });
19
20parser.addArgument('--tc' , { help: 'TC $NoOfTc' } );
21parser.addArgument('--printtc' ,
22 {
23 help: 'Print complete usage help',
24 action: 'storeTrue'
25 }
26 );
27
28var args = parser.parseArgs();
29
30if (args.tc=="100") {
31 console.log("TC: 100")
32}
33if (args.tc=="101") {
34 console.log("TC: 101")
35 //preparations
36}
37if (args.tc=="102") {
38 console.log("TC: 102")
39 //preparations
40}
41
42if (args.printtc) {
43 console.log("TC 100: receive all incoming files");
44 console.log("TC 101: drop/deny first 10 publishing attempt, then receive all");
45 console.log("TC 102: drop/deny/every second publisging attempt");
46 process.exit(0);
47}
48
49var bodyParser = require('body-parser')
50app.use(bodyParser.urlencoded({ extended: false }))
51
52// parse application/json
53app.use(bodyParser.json())
54
55// parse application/vnd.api+json as json
56app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
57
58// parse some custom thing into a Buffer
59app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' }))
60// parse an HTML body into a string
61app.use(bodyParser.text({ type: 'text/html' }))
62app.get("/",function(req, res){
63 res.send("ok");
64})
65app.put('/publish/1/:filename', function (req, res) {
66 console.log(req.files);
67 console.log(req.body);
68 console.log(req.headers);
69 var filename = path.basename(req.params.filename);
70 res.redirect(301, 'http://127.0.0.1:3908/publish/1/'+filename)
71})
72var httpServer = http.createServer(app);
73var httpsServer = https.createServer(credentials, app);
74
75var httpPort=3906
76var httpsPort=3907
77httpServer.listen(httpPort);
78console.log("DR-simulator listening (http) at "+httpPort)
79httpsServer.listen(httpsPort);
80console.log("DR-simulator listening (https) at "+httpsPort)