-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (43 loc) · 1000 Bytes
/
Copy pathserver.js
File metadata and controls
49 lines (43 loc) · 1000 Bytes
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
48
49
//
// Globals
//
var portno = 80; // The network port to listen on.
//includes
var web = require("./web");
var router = require("./router");
var requestHandlers = require("./requestHandlers");
//build possible paths
var handle = {};
handle["/math/get"] = requestHandlers.math.get;
handle["/math/put"] = requestHandlers.math.put;
//
// Start running here.
//
processCmd(); // Process Command Line args.
web.start(router.route, handle, portno);
//
// Command line processing
//
var argvskip = false;
function processCmd() {
process.argv.forEach(function (val, index, array) {
switch(val)
{
case "--port":
case "-p":
portno = array[index+1];
argvskip = true;
break;
default:
if (index >= 2 && argvskip == false) { // TODO Improve way to detect if we're past the node args
printusage();
} else {
argvskip = false;
}
}
});
}
function printusage() {
console.log ("usage: server.js [-p|--port] <portnumber>");
process.exit(1);
}