-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
49 lines (35 loc) · 1.2 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
37
38
39
40
41
42
43
44
45
46
47
48
49
const Koa = require('koa')
//, logger = require('koa-logger') //替换成log4js了,后边需要再说
, json = require('koa-json')
, onerror = require('koa-onerror');
const router = require('./routes');
const log4js = require('./component/log4js');
const httpTools = require('./component/httpTools');
const errorCode = require('./component/errorCode');
const interceptor = require('./interceptor');
const pgpTools = require('./utils/pgpTools');
const commonConfig = require('./config/common_config.json');
const db = require('./db');
let app = new Koa();
// error handler
onerror(app);
app.context.db = db;
app.context.httpTools = httpTools;
app.context.errorCode = errorCode;
app.context.pgpTools = pgpTools;
app.context.commonConfig = commonConfig;
app.use(require('koa-bodyparser')({
enableTypes: ['json', 'form', 'text']
}));
app.use(json());
app.use(log4js.koaLogger());
//app.use(require('koa-static')(__dirname + '/public'));
//app interceptor
app.use(interceptor.routerMethodInterceptor())
// routes definition
app.use(router.routes()).use(router.allowedMethods());
// error-handling
app.on('error', (err, ctx) => {
console.error('server error', err, ctx)
});
module.exports = app;