-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserve.js
executable file
·64 lines (46 loc) · 1.69 KB
/
serve.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
#!/usr/bin/env node
var express = require('express');
var geoip = require('geoipcity');
var dns = require('dns');
var config = require('./config');
var routes = require('./routes');
serve();
function serve(err) {
if(err) return console.error(err);
var prefix = 'v1';
var app = express();
app.configure(function() {
app.set('port', config.port);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
app.configure('development', function() {
app.use(express.errorHandler());
});
app.get('/' + prefix + '/location', routes.location.get);
app.get('/' + prefix + '/ip', routes.ip.get);
app.get('/' + prefix + '/blacklisted/:ip', routes.blacklisted.get);
app.get('/' + prefix + '/ssl', routes.ssl.get);
app.get('/' + prefix + '/ua/:ua', routes.ua.get);
process.on('exit', terminator);
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS',
'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGPIPE', 'SIGTERM'
].forEach(function(element, index, array) {
process.on(element, function() { terminator(element); });
});
var port = config.port;
app.listen(port, function() {
console.log('%s: Node (version: %s) %s started on %d ...', Date(Date.now() ), process.version, process.argv[1], port);
});
}
function terminator(sig) {
if(typeof sig === "string") {
console.log('%s: Received %s - terminating Node server ...',
Date(Date.now()), sig);
process.exit(1);
}
console.log('%s: Node server stopped.', Date(Date.now()) );
}