yanhuanwang | db4bd69 | 2019-03-15 07:57:38 +0000 | [diff] [blame] | 1 | var http = require('http'); |
| 2 | var https = require('https'); |
| 3 | var ArgumentParser = require('argparse').ArgumentParser; |
| 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 | |
| 14 | var parser = new ArgumentParser({ |
| 15 | version: '0.0.1', |
| 16 | addHelp:true, |
| 17 | description: 'Datarouter simulator' |
| 18 | }); |
| 19 | |
| 20 | parser.addArgument('--tc' , { help: 'TC $NoOfTc' } ); |
| 21 | parser.addArgument('--printtc' , |
| 22 | { |
| 23 | help: 'Print complete usage help', |
| 24 | action: 'storeTrue' |
| 25 | } |
| 26 | ); |
| 27 | |
| 28 | var args = parser.parseArgs(); |
| 29 | |
| 30 | if (args.tc=="100") { |
| 31 | console.log("TC: 100") |
| 32 | } |
| 33 | if (args.tc=="101") { |
| 34 | console.log("TC: 101") |
| 35 | //preparations |
| 36 | } |
| 37 | if (args.tc=="102") { |
| 38 | console.log("TC: 102") |
| 39 | //preparations |
| 40 | } |
| 41 | |
| 42 | if (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 | |
| 49 | var bodyParser = require('body-parser') |
| 50 | app.use(bodyParser.urlencoded({ extended: false })) |
| 51 | |
| 52 | // parse application/json |
| 53 | app.use(bodyParser.json()) |
| 54 | |
| 55 | // parse application/vnd.api+json as json |
| 56 | app.use(bodyParser.json({ type: 'application/vnd.api+json' })) |
| 57 | |
| 58 | // parse some custom thing into a Buffer |
| 59 | app.use(bodyParser.raw({limit:1024*1024*20, type: 'application/octet-stream' })) |
| 60 | // parse an HTML body into a string |
| 61 | app.use(bodyParser.text({ type: 'text/html' })) |
| 62 | app.get("/",function(req, res){ |
| 63 | res.send("ok"); |
| 64 | }) |
| 65 | app.post('/webapi/feeds/', function (req, res) { |
| 66 | res.send("ok"); |
| 67 | }) |
| 68 | var httpServer = http.createServer(app); |
| 69 | var httpsServer = https.createServer(credentials, app); |
| 70 | |
| 71 | var httpPort=6665 |
| 72 | var httpsPort=6666 |
| 73 | httpServer.listen(httpPort); |
| 74 | console.log("DR-simulator listening (http) at "+httpPort) |
| 75 | httpsServer.listen(httpsPort); |
| 76 | console.log("DR-simulator listening (https) at "+httpsPort) |