-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (45 loc) · 1.46 KB
/
server.js
File metadata and controls
51 lines (45 loc) · 1.46 KB
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
var Promise = require("bluebird");
var http = require('http');
var httpShutdown = require('http-shutdown');
var express = require('express');
var compression = require('compression');
//var logger = require('morgan');
var db = require('pmt-data-access');
var backend = require('pmt-backend');
var config = require('./config.js');
var app = express();
//app.use(logger('combined'));
app.use(compression());
var server = http.createServer(app);
server = httpShutdown(server);
server = Promise.promisifyAll(server);
db.connect(config.get('db.url'), config)
.then(function () {
backend.addRoutes(server, app, config, db);
return server.listenAsync(config.get('server.port'));
})
.then(function () {
console.log('Started ProfileManagementTool Server - listening on port: ' + config.get('server.port'));
});
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
process.on('SIGHUP', shutdown);
process.on('SIGQUIT', shutdown);
function shutdown() {
return backend.onShutdown()
.then(function () {
return server.shutdownAsync();
})
.then(function () {
return db.close(true);
})
.then(function () {
console.log('Stopped ProfileManagementTool Server');
process.exit(0);
})
.catch(function (err) {
console.error(err);
console.log('Stopped ProfileManagementTool Server');
process.exit(1);
});
}