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(