This commit is contained in:
robin
2022-07-07 22:16:39 +08:00
parent 264ab8d979
commit a9a4bd0981
86 changed files with 1198 additions and 310 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
module.exports = {
path:"middleware/*/index.js"
path:"middleware/*/index.js",
app_path: "app/*/middleware/*/index.js",
}
+9 -3
View File
@@ -2,19 +2,25 @@
* 加载中间件
* 加载app/middleware文件夹下的中间件
*/
const config = require("./config")
module.exports = async (app) => {
let list = await app.load(config.path)
let list2 = await app.load(config.app_path)
list=[...list,...list2]
// Object.assign(list, list2)
list = app.xe.orderBy(list, "res.sort")
list = list.filter(item => item.res.use)
list.forEach(async item => {
console.log('加载的中间件:',item.parse.dir);
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)
})
app.use(async (ctx, next) => {
return await item.res.fun(ctx, next, app)
})
}
})