|
@@ -34,13 +34,33 @@ module.exports = {
|
|
port: port,
|
|
port: port,
|
|
open: true,
|
|
open: true,
|
|
proxy: {
|
|
proxy: {
|
|
- // detail: https://cli.vuejs.org/config/#devserver-proxy
|
|
|
|
|
|
+ // 参考:https://cli.vuejs.org/config/#devserver-proxy
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
target: `http://localhost:8087`,
|
|
target: `http://localhost:8087`,
|
|
changeOrigin: true,
|
|
changeOrigin: true,
|
|
- pathRewrite: {
|
|
|
|
- ['^' + process.env.VUE_APP_BASE_API]: ''
|
|
|
|
- }
|
|
|
|
|
|
+ // 修正 pathRewrite,确保原始路径正确返回
|
|
|
|
+ // pathRewrite: (pathReq, req) => {
|
|
|
|
+ // const baseApi = process.env.VUE_APP_BASE_API;
|
|
|
|
+ // // 兼容 baseApi 为空或未定义的情况
|
|
|
|
+ // if (!baseApi) {
|
|
|
|
+ // console.error('[Proxy PathRewrite] VUE_APP_BASE_API 未配置,无法进行路径重写');
|
|
|
|
+ // return pathReq;
|
|
|
|
+ // }
|
|
|
|
+ // // 只替换以 baseApi 开头的路径,避免误替换
|
|
|
|
+ // if (pathReq.startsWith(baseApi)) {
|
|
|
|
+ // const newPath = pathReq.replace(new RegExp('^' + baseApi), '');
|
|
|
|
+ // console.log(`[Proxy PathRewrite] 原始路径: ${pathReq},重写后: ${newPath},${newPath === pathReq ? '未发生路径重写,请检查 VUE_APP_BASE_API 配置' : '路径重写成功'}`);
|
|
|
|
+ // return newPath;
|
|
|
|
+ // } else {
|
|
|
|
+ // // 如果路径未以 baseApi 开头,直接返回原始路径并提示
|
|
|
|
+ // console.warn(`[Proxy PathRewrite] 原始路径: ${pathReq} 未以 ${baseApi} 开头,未进行重写`);
|
|
|
|
+ // return pathReq;
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // logLevel: 'debug',
|
|
|
|
+ // onProxyReq: (proxyReq, req) => {
|
|
|
|
+ // console.log('[HPM]', process.env.NODE_ENV, req.method, req.originalUrl, '->', req.url);
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
disableHostCheck: true
|
|
disableHostCheck: true
|