forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (44 loc) · 1.23 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const Koa = require('koa')
const views = require('koa-views')
const json = require('koa-json')
const onerror = require('koa-onerror')
const bodyparser = require('koa-bodyparser')
const logger = require('koa-logger')
const koaStatic = require('koa-static')
const less = require('./middleware/koa-less')
const addr = require('./middleware/koa-addr')
const paths = require('./middleware/koa-paths')
const routers = require('./routers/index')
const cors = require('@koa/cors');
// const proxy = require('./utils/proxy')
const app = new Koa()
onerror(app)
app.use(cors())
app.use(bodyparser({
enableTypes:['json', 'form', 'text']
}))
app.use(json())
app.use(addr)
app.use(paths)
// 配置控制台日志中间件
app.use(logger())
//less 中间件
app.use(less(__dirname + '/public'))
// 配置静态资源加载中间件
app.use(koaStatic(__dirname + '/public'))
// 配置服务端模板渲染引擎中间件
app.use(views(__dirname + '/views', {
extension: 'pug'
}))
// 初始化路由中间件
app.use(routers.routes()).use(routers.allowedMethods())
app.use(async (ctx) => {
console.log(ctx.status);
switch (ctx.status) {
case 404:
await ctx.render('404');
break;
}
})
// proxy.start(5002)
module.exports = app