blob: cca85f98bac40b31cf254d0b7c10a4798113d712 [file] [log] [blame]
yanhuanwangdb4bd692019-03-15 07:57:38 +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.post('/webapi/feeds/', function (req, res) {
66 res.send("ok");
67})
68var httpServer = http.createServer(app);
69var httpsServer = https.createServer(credentials, app);
70
71var httpPort=6665
72var httpsPort=6666
73httpServer.listen(httpPort);
74console.log("DR-simulator listening (http) at "+httpPort)
75httpsServer.listen(httpsPort);
76console.log("DR-simulator listening (https) at "+httpsPort)