From 5184672b61aabaa28d6855d2264fc36e80da7b46 Mon Sep 17 00:00:00 2001 From: let5sne Date: Mon, 20 Jul 2026 13:55:50 +0800 Subject: [PATCH] fix(mobile): default h5 dev proxy to local backend on 8080 Bare npm run dev (including hosted preview sessions) has no portless route, so the previous default target https://wygj-api.localhost was unreachable and every API call failed with HTTP 500. scripts/dev.sh now passes VITE_PROXY_TARGET explicitly, keeping the portless flow intact. --- mobile-uni/vite.config.ts | 4 +++- scripts/dev.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mobile-uni/vite.config.ts b/mobile-uni/vite.config.ts index 864940bb..430c63cf 100644 --- a/mobile-uni/vite.config.ts +++ b/mobile-uni/vite.config.ts @@ -4,7 +4,9 @@ import uniPlugin from '@dcloudio/vite-plugin-uni'; const uni = typeof uniPlugin === 'function' ? uniPlugin : uniPlugin.default; const devPort = Number(process.env.PORT) || 5175; const devHost = process.env.HOST || '0.0.0.0'; -const proxyTarget = process.env.VITE_PROXY_TARGET || 'https://wygj-api.localhost'; +// 裸跑 npm run dev(如 Kimi Work 预览)时代理到本地 8080 后端; +// 走 portless(scripts/dev.sh)时由 VITE_PROXY_TARGET 显式指向 https://wygj-api.localhost +const proxyTarget = process.env.VITE_PROXY_TARGET || 'http://127.0.0.1:8080'; // 代理到线上等已带 /dev-api 前缀的网关时,设 VITE_PROXY_KEEP_PREFIX=1 保留前缀 const keepProxyPrefix = process.env.VITE_PROXY_KEEP_PREFIX === '1'; diff --git a/scripts/dev.sh b/scripts/dev.sh index 1a69d98c..c1fb8f79 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -249,7 +249,7 @@ PIDS+=("$!") if using_portless_mobile; then portless alias --remove wygj-mobile-uni >/dev/null 2>&1 || true - portless run --name wygj-mobile-uni --force npm --prefix mobile-uni run dev & + VITE_PROXY_TARGET="${VITE_PROXY_TARGET:-https://wygj-api.localhost}" portless run --name wygj-mobile-uni --force npm --prefix mobile-uni run dev & else ./scripts/dev-mobile.sh & fi