fix: 代理插件兼容 array 写法

This commit is contained in:
winixt 2024-11-27 11:16:29 +08:00
parent efd8708752
commit b68ca092ed

View File

@ -6,8 +6,15 @@ const ASSET_EXT_NAMES = ['.ico', '.png', '.jpg', '.jpeg', '.gif', '.svg'];
function proxyMiddleware(api) { function proxyMiddleware(api) {
return (req, res, next) => { return (req, res, next) => {
const proxyConfig = api.config.proxy; const proxyConfig = api.config.proxy;
if (proxyConfig && Object.keys(proxyConfig).some(path => req.url.startsWith(path))) { if (proxyConfig) {
return next(); if (Array.isArray(proxyConfig)) {
if (proxyConfig.some(item => item.context.some(path => path && req.url.startsWith(path)))) {
return next();
}
}
else if (Object.keys(proxyConfig).some(path => req.url.startsWith(path))) {
return next();
}
} }
if (ASSET_EXT_NAMES.includes(extname(req.url))) { if (ASSET_EXT_NAMES.includes(extname(req.url))) {
return next(); return next();