forked from icfi-tech-crunch-munch/get-with-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
68 lines (51 loc) · 1.54 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
66
67
68
var express = require('express');
var session = require('express-session');
//local variable declaration
var shutting_down = false;
var server = null;
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var app = express();
app.set('views', __dirname + '/server/views');
app.set('view engine', 'jade');
app.use(express.static(__dirname + '/public'));
app.disable("x-powered-by");
app.use(session({
secret: "Kuj6Gf",
key: "sessionId",
saveUninitialized: true,
resave: true,
cookie: {
httpOnly: true,
secure: true
}
}));
app.use(function (req, resp, next) {
if(!shutting_down)
return next();
resp.setHeader('Connection', "close");
resp.send(503, "Server is in the process of restarting");
// Change the response to something your client is expecting:
// html, text, json, etc.
});
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
app.get('*', function (req, res) {
res.render('index');
});
server = app.listen(app.get('port'), app.get('host'), function () {
console.log("Express server listening on port " + app.get('port'));
});
function cleanup () {
shutting_down = true;
server.close( function () {
console.log( "Closed out remaining connections.");
// Close db connections, other chores, etc.
process.exit();
});
setTimeout( function () {
console.error("Could not close connections in time, forcing shut down");
process.exit(1);
}, 30*1000);
}
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);