From b0c1c7209be16c56d7496b080b599d736887b575 Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 16 Sep 2026 22:19:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(config):=20=E7=94=9F=E4=BA=A7=E6=9E=84?= =?UTF-8?q?=E5=BB=BA(Tauri=E6=89=93=E5=8C=85)=E9=BB=98=E8=AE=A4=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E7=94=9F=E4=BA=A7=20opc.pinesound.cn=20+=20=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=9C=B0=E5=9D=80=E8=AF=8A=E6=96=AD=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolveHost:生产构建且运行于 Tauri WebView 时默认回退 opc.pinesound.cn(不再回退局域网 192.168.1.9), 即使 config.json / .env 缺失也能接入生产;本地 dev 仍回退局域网 - main.jsx:bootstrap 后打印最终生效 API_BASE / MQTT_URL / MQTT_USER,便于定位地址切换问题 - 已验证构建产物:烘焙 https://opc.pinesound.cn/park,无 192.168.1.9:8090 / 192.168.1.3:8083 残留 --- src/config.js | 9 +++++---- src/main.jsx | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/config.js b/src/config.js index 8325e53..ba409f2 100644 --- a/src/config.js +++ b/src/config.js @@ -11,10 +11,11 @@ const env = import.meta.env || {}; /* 运行期解析(惰性读取 window.__DPM_*__,供 main.jsx bootstrap 覆盖后再生效) */ function resolveHost() { - const h = window.location.hostname || '192.168.1.9'; - // Tauri 打包 WebView(tauri.localhost / localhost)→ 服务同机部署用 192.168.1.9 - if (h === 'tauri.localhost' || h === 'localhost' || h === '192.168.1.9' || h.includes('tauri')) { - return '192.168.1.9'; + const h = window.location.hostname || 'opc.pinesound.cn'; + // Tauri 打包 WebView(tauri.localhost / localhost)→ 生产构建默认接入生产 opc.pinesound.cn; + // 本地开发(npm run dev)仍回退局域网测试机 192.168.1.9 + if (h === 'tauri.localhost' || h === 'localhost' || h.includes('tauri')) { + return import.meta.env.PROD ? 'opc.pinesound.cn' : '192.168.1.9'; } return h; // 浏览器开发/局域网:当前主机 IP } diff --git a/src/main.jsx b/src/main.jsx index f444e69..0136538 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -5,7 +5,7 @@ import BindScreen from "./components/BindScreen.jsx"; import { isDeviceBound } from "./utils/tenant"; import ErrorBoundary from "./components/ErrorBoundary"; import { ThemeProvider } from "@appica/ui-react/providers/theme-provider"; -import { getApiBase } from "./config"; +import { getApiBase, getMqttUrl, getMqttCredentials } from "./config"; import { invoke } from "@tauri-apps/api/core"; import "./styles/global.css"; @@ -80,6 +80,10 @@ async function bootstrapRuntimeConfig() { } bootstrapRuntimeConfig().then(() => { + // 启动诊断:打印最终生效的 API / MQTT 地址(config.json > 构建烘焙 > /api/config 下发 > 内置默认) + try { + console.info(`[bootstrap] API_BASE=${getApiBase()} MQTT_URL=${getMqttUrl()} MQTT_USER=${getMqttCredentials().username || "(空)"}`); + } catch (e) { /* 忽略 */ } ReactDOM.createRoot(document.getElementById("root")).render(