egg-xc-base
Version:
a base framework with egg.js
22 lines (19 loc) • 772 B
JavaScript
;
const assert = require('assert');
module.exports = async app => {
// 将formatCookie中间件添加到jwt中间件之前
const jwtIndex = app.config.coreMiddleware.indexOf('jwt');
if (jwtIndex >= 0) {
app.config.coreMiddleware.splice(jwtIndex - 1, 0, 'formatCookie');
} else {
app.config.coreMiddleware.unshift('formatCookie');
}
app.config.coreMiddleware.unshift('gzip');
// 统一错误处理中间件
app.config.coreMiddleware.unshift('errorHandler');
const index = app.config.coreMiddleware.indexOf('bodyParser');
assert(index >= 0, 'bodyParser 中间件必须存在');
// 将report插件添加到bodyParser插件之后
app.config.coreMiddleware.splice(index + 1, 0, 'report');
await require('./lib/initApi')(app);
};