Skip to content

createHtmlPlugin 对 server.proxy 的处理有点问题 #167

@ArcherZhao

Description

@ArcherZhao

对于类似于 '^/test/api/.*'这种key的形式会匹配不到,createRewire函数需要改一下。比如改成如下形式:
function createRewire(reg, page, baseUrl, proxyUrlKeys) {
return {
from: new RegExp(^/${reg}*),
to({ parsedUrl }) {
const pathname = parsedUrl.path;
const excludeBaseUrl = pathname.replace(baseUrl, "/");
const template = path.resolve(baseUrl, page.template);
if (excludeBaseUrl.startsWith("/static")) {
return excludeBaseUrl;
}
if (excludeBaseUrl === "/") {
return template;
}
const isApiUrl = proxyUrlKeys.some((item) => {
try {
const regex = new RegExp(item);
return regex.test(pathname);
} catch (e) {
// 如果不是有效的正则表达式,则回退到原来的匹配方式
return pathname.startsWith(path.resolve(baseUrl, item));
}
});
return isApiUrl ? parsedUrl.path : template;
}
};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions