优化架构,新增路由

This commit is contained in:
robin
2022-06-04 11:43:05 +08:00
parent ba9ca43729
commit 264ab8d979
22 changed files with 161 additions and 60 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
module.exports = {
path:"middleware/*.js"
path:"middleware/*/index.js"
}
+10 -4
View File
@@ -7,9 +7,15 @@ module.exports = async (app) => {
let list = await app.load(config.path)
list = app.xe.orderBy(list, "res.sort")
list = list.filter(item => item.res.use)
list.forEach(item => {
app.use(async (ctx, next) => {
return await item.res.fun(ctx, next)
})
list.forEach(async item => {
if (item.res.loadFun) {
//如果中间件定义了特殊加载方法
await item.res.loadFun(app, item.res.fun)
} else {
app.use(async (ctx, next) => {
return await item.res.fun(ctx, next, app)
})
}
})
}