-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.js
34 lines (25 loc) · 885 Bytes
/
index.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
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const logger = require('./utils/logger');
const config = require('./config');
const mongodb = require('./utils/mongodb');
const redis = require('./utils/redis');
const onerror = require('./middleware/onerror');
const header = require('./middleware/header.js');
const accessControl = require('./middleware/access-control.js');
const router = require('./router');
process.on('uncaughtException', (e) => {
logger.error('uncaughtException: ' + e);
});
logger.info('🎉 DPlayer start! Cheers!');
const app = new Koa();
app.proxy = true;
app.context.mongodb = mongodb;
app.context.redis = redis;
app.use(bodyParser());
app.use(onerror);
app.use(header);
app.use(accessControl);
app.use(router.routes()).use(router.allowedMethods());
app.listen(config.port);
logger.info('Listening Port ' + config.port);