fix(config): 生产构建(Tauri打包)默认回退生产 opc.pinesound.cn + 启动地址诊断日志
- 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 残留
This commit is contained in:
+5
-4
@@ -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
|
||||
}
|
||||
|
||||
+5
-1
@@ -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(
|
||||
<React.StrictMode>
|
||||
<ErrorBoundary>
|
||||
|
||||
Reference in New Issue
Block a user