-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetnoder.js
48 lines (40 loc) · 1.41 KB
/
netnoder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var arguments = require('yargs').argv;
var netnoder = parseCommandLineData(arguments.netnoder);
function parseCommandLineData(json) {
return JSON.parse(json.split('<netnoderdq>').join('"').split('<netnodersq>').join("'"));
}
module.exports = function (expressApp) {
var bodyParser = require('body-parser');
// parse application/json
expressApp.use(bodyParser.json());
// Set routes for ping and kill
expressApp.post('/netnoderping', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text'
});
res.end('1');
}).post('/netnoderkill', function(req, res) {
//If password matches, kill the process and resp
if (req.body.pw === netnoder.killPassword) {
res.writeHead(200, {
'Content-Type': 'text'
});
res.end('Accepted');
process.exit(0);
return;
}
// Wrong password provided, respond with generic message
res.writeHead(500, {
'Content-Type': 'text'
});
res.end('Posts not allowed');
});
netnoder.listen = function() {
var args = Array.prototype.slice.call(arguments);
// Insert host and port at the beginning of the arguments
args.unshift(netnoder.location.port,netnoder.location.host);
// Start server
expressApp.listen.apply(expressApp,args);
};
return netnoder;
};