22 lines
526 B
JavaScript
22 lines
526 B
JavaScript
/**
|
|
* 加载中间件
|
|
* 加载app/middleware文件夹下的中间件
|
|
*/
|
|
const config = require("./config")
|
|
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(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)
|
|
})
|
|
}
|
|
|
|
})
|
|
}
|