-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (29 loc) · 890 Bytes
/
Copy pathapp.js
File metadata and controls
34 lines (29 loc) · 890 Bytes
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 path = require('path');
const Koa = require('koa');
const render = require('koa-art-template');
const bodyparser = require('koa-bodyparser');
const static = require('koa-static');
const {router, getCommonData} = require('./router');
const app = new Koa();
app.use(bodyparser());
app.use(static(
path.join(__dirname, './static')
));
render(app, {
root: path.join(__dirname, 'view'),
debug: process.env.NODE_ENV !== 'production'
});
app.use(router.routes()).use(router.allowedMethods());
app.use(async ctx => {
if (ctx.status === 404) {
let commonData = await getCommonData();
await ctx.render('./404', {
message: '页面不存在',
individuation: commonData.individuation,
sideBar: commonData.sideBar,
});
}
});
app.listen(3000, () => {
console.log('server running at http://localhost:3000');
});