Skip to content

Commit

Permalink
fix: 静态资源进入 middleware, proxy middleware 插入需要在静态资源和自定义中间件前面
Browse files Browse the repository at this point in the history
  • Loading branch information
sky committed Feb 5, 2021
1 parent e7d8980 commit 2231440
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ module.exports = app => {
} else if (config.proxy.force !== true) {
config.proxy.host = `http://127.0.0.1:${port}`;
}
app.middleware.splice(app.middleware.length - 2, 0, convert(proxy(config.proxy)));
// 解决 proxy middleware 插入需要在静态资源和自定义中间件前面
let proxyIndex = -1;
const mwNames = ['static', 'bodyParser', 'overrideMethod', 'session', 'securities', 'notfound', 'siteFile', 'meta'];
while (mwNames.length) {
const name = mwNames.shift();
proxyIndex = app.middleware.findIndex(mw => {
return mw._name === name;
});
if (proxyIndex > -1) {
break;
}
}
app.middleware.splice(proxyIndex, 0, convert(proxy(config.proxy)));
}
});

Expand Down

0 comments on commit 2231440

Please sign in to comment.