-
Notifications
You must be signed in to change notification settings - Fork 27
/
app.js
36 lines (27 loc) · 1.01 KB
/
app.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
require('app-module-path').addPath(__dirname);
const Koa = require('koa');
const http = require('http');
const config = require('config');
const logger = require('logger');
const cors = require('@koa/cors');
const helmet = require('koa-helmet');
const qs = require('koa-qs');
const bodyParser = require('koa-bodyparser');
const requestLogger = require('koa-logger');
const routes = require('routes');
process.on('unhandledRejection', (reason, p) => {
logger.error('Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason);
});
const app = new Koa();
app.use(cors({ credentials: true }));
app.use(helmet());
qs(app);
app.use(bodyParser({ enableTypes: ['json', 'form', 'text'] }));
app.use(requestLogger());
routes(app);
const server = http.createServer(app.callback());
require('services/socket/socket.service')(server);
server.listen(config.port, () => {
logger.warn(`Api server listening on ${config.port}, in ${process.env.NODE_ENV} mode and ${process.env.APP_ENV} environment`);
});
module.exports = app;