diff --git a/.env.example b/.env.example index 177b0a47..ffaf65f9 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,10 @@ VITE_API_BASE_URL=/api # 按本机联调环境填写国内 Gateway origin,不提交真实环境地址。 API_PROXY_TARGET=http://localhost:9000 +# 可选:本地分别直连 Auth、IAM、Warehouse;未设置时复用 API_PROXY_TARGET。 +# AUTH_API_PROXY_TARGET=http://localhost:9001 +# IAM_API_PROXY_TARGET=http://localhost:9002 +# WAREHOUSE_API_PROXY_TARGET=http://localhost:9003 # 海外业务浏览器请求使用独立代理,代理会将 /overseas-api 重写为海外 Gateway 的 /api。 VITE_OVERSEAS_API_BASE_URL=/overseas-api # 按本机联调环境填写海外 Gateway origin,不提交真实环境地址。 diff --git a/vite.config.ts b/vite.config.ts index 653bfe6c..f8e12e3b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,6 +8,9 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const proxyTarget = env.API_PROXY_TARGET || 'http://localhost:8080' + const authProxyTarget = env.AUTH_API_PROXY_TARGET || proxyTarget + const iamProxyTarget = env.IAM_API_PROXY_TARGET || proxyTarget + const warehouseProxyTarget = env.WAREHOUSE_API_PROXY_TARGET || proxyTarget const overseasProxyTarget = env.OVERSEAS_API_PROXY_TARGET || 'http://localhost:9300' return { @@ -30,6 +33,33 @@ export default defineConfig(({ mode }) => { server: { strictPort: true, proxy: { + '/api/auth': { + target: authProxyTarget, + changeOrigin: true, + configure(proxy) { + proxy.on('proxyReq', (proxyRequest) => { + proxyRequest.removeHeader('origin') + }) + }, + }, + '/api/platform/v1/iam': { + target: iamProxyTarget, + changeOrigin: true, + configure(proxy) { + proxy.on('proxyReq', (proxyRequest) => { + proxyRequest.removeHeader('origin') + }) + }, + }, + '/api/platform/v1/warehouse-admin': { + target: warehouseProxyTarget, + changeOrigin: true, + configure(proxy) { + proxy.on('proxyReq', (proxyRequest) => { + proxyRequest.removeHeader('origin') + }) + }, + }, '/api': { target: proxyTarget, changeOrigin: true,