-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
39 lines (35 loc) · 851 Bytes
/
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
const http = require('http');
const koa = require('koa');
const debug = require('debug')(process.env.DEBUG);
const json = require('koa-json');
const {app : config} = require('./config');
const error = require('./middleware/error');
const {routes, allowedMethods} = require('./src/routes');
debug('Booting %s', config.name);
const app = new koa();
/**
* Start server
*
* @type {Server|*}
*/
const server = http.createServer(app.callback())
.listen(process.env.HTTP_PORT, () => {
debug('%s is available at http://%s:%d',
config.name,
process.env.HTTP_HOST,
process.env.HTTP_PORT);
}).on('close', () => {
debug('Server shutdown.');
});
app.use(allowedMethods());
app.use(routes());
app.use(error);
app.use(json);
/**
* Shutdown server eve
*/
process.on('SIGINT', () => {
server.close(() => {
process.exit(0);
});
});