From 6adf57c4bbfd741c40e7dbc5cda51d8fe41e220d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A6=8F=E8=B4=A2?= <1471584931@qq.com> Date: Wed, 26 Nov 2025 10:27:11 +0800 Subject: [PATCH] =?UTF-8?q?--=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=90=86=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++-- build/vite/proxy.ts | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.env.development b/.env.development index 82cb13a..36e7c02 100644 --- a/.env.development +++ b/.env.development @@ -10,8 +10,8 @@ VITE_PUBLIC_PATH = / # 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题 # 可以有多个,注意多个不能换行,否则代理将会失效 #VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]] -#VITE_PROXY=[["/api","http://47.94.165.164: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","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 VITE_DROP_CONSOLE = false diff --git a/build/vite/proxy.ts b/build/vite/proxy.ts index abe82a9..2423ba0 100644 --- a/build/vite/proxy.ts +++ b/build/vite/proxy.ts @@ -1,6 +1,3 @@ -/** - * Used to parse the .env.development proxy configuration - */ import type { ProxyOptions } from 'vite'; type ProxyItem = [string, string]; @@ -17,8 +14,9 @@ const httpsRE = /^https:\/\//; */ export function createProxy(list: ProxyList = []) { const ret: ProxyTargetList = {}; - for (const [prefix, target] of list) { + for (const [prefix, target, replaceStr] of list) { const isHttps = httpsRE.test(target); + console.log(`Proxy config loaded: ${prefix} => ${target}`); if (prefix.length > 255) { throw new Error('字符长度超出255个字符'); } @@ -28,10 +26,18 @@ export function createProxy(list: ProxyList = []) { changeOrigin: true, ws: true, 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 ...(isHttps ? { secure: false } : {}), }; } + + // 添加调试日志,显示所有代理配置 + console.log('All proxy configurations:', ret); return ret; -} +} \ No newline at end of file