ec-router
Version:
一个koa2自动路由中间件,直接根椐请求方法及路径路由到指定的controller。无需人工编写路由表或映射
18 lines (16 loc) • 385 B
JavaScript
module.exports = {
//do before all controller action
before : (ctx) => {
ctx.myHeader = 'before_'
},
//do after all controller action
after: (ctx) => {
ctx.myHeader += '_after'
ctx.set('_hook',ctx.myHeader)
},
error:(ctx,err) =>{
ctx.status = err.code
ctx.body = err.error
//console.log(err)
}
}