diff --git a/services/gateway-service/configs/config.docker.yaml b/services/gateway-service/configs/config.docker.yaml index af67244f..c959e744 100644 --- a/services/gateway-service/configs/config.docker.yaml +++ b/services/gateway-service/configs/config.docker.yaml @@ -15,6 +15,13 @@ cors: - "http://127.0.0.1:3000" - "http://localhost:5173" - "http://127.0.0.1:5173" + # 本地工具页会用 10300/8787/8788 承载静态 HTML;精确放行测试端口,避免用 "*" 破坏凭证请求边界。 + - "http://localhost:10300" + - "http://127.0.0.1:10300" + - "http://localhost:8787" + - "http://127.0.0.1:8787" + - "http://localhost:8788" + - "http://127.0.0.1:8788" - "https://global-interaction.com" - "https://www.global-interaction.com" - "https://h5.global-interaction.com" diff --git a/services/gateway-service/configs/config.yaml b/services/gateway-service/configs/config.yaml index 33b301b6..8e7f2051 100644 --- a/services/gateway-service/configs/config.yaml +++ b/services/gateway-service/configs/config.yaml @@ -15,6 +15,13 @@ cors: - "http://127.0.0.1:3000" - "http://localhost:5173" - "http://127.0.0.1:5173" + # 本地工具页会用 10300/8787/8788 承载静态 HTML;精确放行测试端口,避免用 "*" 破坏凭证请求边界。 + - "http://localhost:10300" + - "http://127.0.0.1:10300" + - "http://localhost:8787" + - "http://127.0.0.1:8787" + - "http://localhost:8788" + - "http://127.0.0.1:8788" - "https://global-interaction.com" - "https://www.global-interaction.com" - "https://h5.global-interaction.com" diff --git a/tools/baishun-game-test.html b/tools/baishun-game-test.html index ce6efbd8..aa109c1b 100644 --- a/tools/baishun-game-test.html +++ b/tools/baishun-game-test.html @@ -155,13 +155,27 @@ const $ = (id) => document.getElementById(id); const defaultApiBase = "https://api-test.global-interaction.com"; const isLocalProxy = ["localhost", "127.0.0.1", "::1"].includes(window.location.hostname); + const bundledProxyPorts = new Set(["8787", "8788"]); + const isBundledProxy = isLocalProxy && bundledProxyPorts.has(window.location.port); + const localDirectApiBasePattern = /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/; $("token").value = localStorage.getItem("baishun_test_access_token") || ""; $("account").value = localStorage.getItem("baishun_test_account") || ""; const savedApiBase = localStorage.getItem("baishun_test_api_base") || ""; - $("apiBase").value = isLocalProxy && (!savedApiBase || savedApiBase === defaultApiBase) ? "" : (savedApiBase || defaultApiBase); + $("apiBase").value = initialApiBase(savedApiBase); $("appCode").value = localStorage.getItem("baishun_test_app_code") || $("appCode").value; + function initialApiBase(savedValue) { + const saved = savedValue.trim().replace(/\/+$/, ""); + // 仓库自带 Node 代理默认监听 8787,本地占用时可切到 8788;空 API Base 会让请求走同源 /api 转发。Python 等纯静态服务 + // 没有这个代理能力,因此必须保留用户手动填写的本地 gateway 地址,交给 gateway CORS 白名单处理。 + if (isLocalProxy && (!saved || saved === defaultApiBase || (isBundledProxy && localDirectApiBasePattern.test(saved)))) { + localStorage.setItem("baishun_test_api_base", ""); + return ""; + } + return saved || defaultApiBase; + } + function apiBase() { return $("apiBase").value.trim().replace(/\/+$/, ""); } diff --git a/tools/lucky-gift-test.html b/tools/lucky-gift-test.html index 13b5de23..480dfc4e 100644 --- a/tools/lucky-gift-test.html +++ b/tools/lucky-gift-test.html @@ -158,6 +158,15 @@ pool_id +