-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (29 loc) · 828 Bytes
/
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
const Koa = require('koa');
const views = require('koa-views');
const nunjucks = require('nunjucks');
const session = require('koa-generic-session');
const redisStore = require('koa-redis');
const convert = require('koa-convert');
const csrf = require('koa-csrf');
const logger = require('./kits/logger_kit');
const routers = require('./routers');
const siteCfg = require('./configs/site_cfg');
const app = new Koa();
app.use(convert(session({
store: redisStore(siteCfg.redis),
})));
app.use(convert(csrf()));
app.use(views(siteCfg.view_path, {
map: {
html: 'nunjucks',
},
}));
// nunjucks配置
nunjucks.configure(siteCfg.view_path);
app.use(routers.routes());
app.listen(siteCfg.port, () => {
logger.info({
port: siteCfg.port,
env: app.env,
}, '服务器启动信息');
});