--修改代理配置
This commit is contained in:
@ -10,8 +10,8 @@ VITE_PUBLIC_PATH = /
|
|||||||
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
|
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
|
||||||
# 可以有多个,注意多个不能换行,否则代理将会失效
|
# 可以有多个,注意多个不能换行,否则代理将会失效
|
||||||
#VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]]
|
#VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]]
|
||||||
#VITE_PROXY=[["/api","http://47.94.165.164:9500"]]
|
#VITE_PROXY=[["/api","http://10.10.2.102:9500"]]
|
||||||
VITE_PROXY=[["/api/sales","http://127.0.0.1:8096/sales"],["/api/mdm","http://127.0.0.1:8096/mdm"],["/api","http://10.10.2.102:9500"]]
|
VITE_PROXY=[["/api/system/generator/","http://127.0.0.1:8091/system/generator/"],["/api/sales/","http://127.0.0.1:8096","/sales/"],["/api/mdm/","http://127.0.0.1:8096","/mdm/"],["/api","http://10.10.2.102:9500"]]
|
||||||
|
|
||||||
# 是否删除Console.log
|
# 是否删除Console.log
|
||||||
VITE_DROP_CONSOLE = false
|
VITE_DROP_CONSOLE = false
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
/**
|
|
||||||
* Used to parse the .env.development proxy configuration
|
|
||||||
*/
|
|
||||||
import type { ProxyOptions } from 'vite';
|
import type { ProxyOptions } from 'vite';
|
||||||
|
|
||||||
type ProxyItem = [string, string];
|
type ProxyItem = [string, string];
|
||||||
@ -17,8 +14,9 @@ const httpsRE = /^https:\/\//;
|
|||||||
*/
|
*/
|
||||||
export function createProxy(list: ProxyList = []) {
|
export function createProxy(list: ProxyList = []) {
|
||||||
const ret: ProxyTargetList = {};
|
const ret: ProxyTargetList = {};
|
||||||
for (const [prefix, target] of list) {
|
for (const [prefix, target, replaceStr] of list) {
|
||||||
const isHttps = httpsRE.test(target);
|
const isHttps = httpsRE.test(target);
|
||||||
|
console.log(`Proxy config loaded: ${prefix} => ${target}`);
|
||||||
if (prefix.length > 255) {
|
if (prefix.length > 255) {
|
||||||
throw new Error('字符长度超出255个字符');
|
throw new Error('字符长度超出255个字符');
|
||||||
}
|
}
|
||||||
@ -28,10 +26,18 @@ export function createProxy(list: ProxyList = []) {
|
|||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
ws: true,
|
ws: true,
|
||||||
timeout: 600000,
|
timeout: 600000,
|
||||||
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
rewrite: (path) => {
|
||||||
|
// 添加日志以便调试路径重写
|
||||||
|
let reStr = replaceStr==undefined?'':replaceStr;
|
||||||
|
console.log(`Proxy triggered - Rewriting path: ${path} => ${target+ path.replace(new RegExp(`^${prefix}`),reStr)}`);
|
||||||
|
return path.replace(new RegExp(`^${prefix}`), reStr);
|
||||||
|
},
|
||||||
// https is require secure=false
|
// https is require secure=false
|
||||||
...(isHttps ? { secure: false } : {}),
|
...(isHttps ? { secure: false } : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加调试日志,显示所有代理配置
|
||||||
|
console.log('All proxy configurations:', ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user