This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
executable file
·66 lines (54 loc) · 1.88 KB
/
server.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
65
#!/bin/env node
var express = require('express');
var http = require('http')
, fs = require('fs')
, path = require('path');
var ipaddr = process.env.VARNAM_IP_ADDRESS;
var port = process.env.VARNAM_WEB_PORT || 3000;
// Create "express" server.
app = express();
app.configure(function(){
app.set('port', port);
app.set('root_directory', __dirname);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set('view cache', true);
app.use(express.favicon());
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
});
if (typeof ipaddr === "undefined") {
console.warn('No IP_ADDRESS environment variable');
}
// terminator === the termination handler.
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()) );
}
// Process on exit and signals.
process.on('exit', function() { 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); });
});
if (process.env.VARNAM_NO_MYSQL === undefined) {
var db = require("./lib/varnamdb");
db.createSchema();
}
var routes = require('./routes')
// And start the app on that interface (and port).
app.listen(port, ipaddr, function() {
console.log('%s: Node server started on %s:%d ...', Date(Date.now() ),
ipaddr, port);
});