-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (57 loc) · 1.45 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var srv = require('./app/server');
var Server = new srv.Server();
module.exports.Server = Server;
// ===== Command Line =============================================================================
var port = 3000;
var usage = ''
+ 'Usage: app.js [options]'
+ '\n'
+ '\nOptions:'
+ '\n -p, --port NUM Port number for server, default is ' + port.toString()
+ '\n -r, --routes Display routes'
+ '\n -h, --help Display help information'
+ '\n';
// Parse arguments
var args = process.argv.slice(2);
var printRoutes = false;
while (args.length) {
var arg = args.shift();
switch (arg) {
case '-h':
case '--help':
console.error(usage + '\n');
process.exit(1);
break;
case '-p':
case '--port':
if (arg = args.shift()) {
port = parseInt(arg, 10);
} else {
throw new Error('--port requires a number');
}
break;
case '-r':
case '--routes':
printRoutes = true;
break;
default:
break;
}
}
// print routes if requested
if (printRoutes) {
console.log("ROUTES:\n" + Server.routes.join("\n") + "\n");
}
// Last safety net
process.on('uncaughtException', function(error) {
var errorMessage = "UNCAUGHT EXCEPTION: " + (error.stack ? error.stack : error);
Server.shutdown(errorMessage);
});
// initialize and start server
Server.init(function(err) {
if (err) {
console.log(err);
} else {
Server.start({port:port});
}
});