diff --git a/src/config.js b/src/config.js index ba409f2..42e2767 100644 --- a/src/config.js +++ b/src/config.js @@ -34,9 +34,14 @@ const _isLegacyVision = (u) => !!(u && (String(u).includes(':10085') || String(u const _visionFromWindow = window.__DPM_VISION__ && !_isLegacyVision(window.__DPM_VISION__) ? window.__DPM_VISION__ : null; const _visionFromEnv = env.VITE_VISION_API_BASE && !_isLegacyVision(env.VITE_VISION_API_BASE) ? env.VITE_VISION_API_BASE : null; export const VISION_API_BASE = (_visionFromWindow || _visionFromEnv || '').replace(/\/$/, ''); -export const MQTT_URL = window.__DPM_MQTT__ || env.VITE_MQTT_URL || `ws://${resolveHost()}:8083/mqtt`; +// MQTT 地址:生产默认走 wss://(TLS);本地开发走 ws://。 +// 若 broker 侧未启用 TLS,请用构建期 VITE_MQTT_URL 或 /api/config 下发覆盖为 ws://。 +const _mqttScheme = import.meta.env.PROD ? 'wss' : 'ws'; +export const MQTT_URL = window.__DPM_MQTT__ || env.VITE_MQTT_URL || `${_mqttScheme}://${resolveHost()}:8083/mqtt`; export const MQTT_USERNAME = window.__DPM_MQTT_USER__ || env.VITE_MQTT_USERNAME || ''; export const MQTT_PASSWORD = window.__DPM_MQTT_PASS__ || env.VITE_MQTT_PASSWORD || ''; +// 大屏引导令牌(/park/api/config 鉴权):window.__DPM_BOOTSTRAP__ > 构建期 VITE_PARK_BOOTSTRAP_TOKEN +export const PARK_BOOTSTRAP_TOKEN = window.__DPM_BOOTSTRAP__ || env.VITE_PARK_BOOTSTRAP_TOKEN || ''; /** 惰性读取 API 基址(仅接受 server-core 地址,旧 :10085 一律回退到 :8090/park) */ export function getApiBase() { diff --git a/src/main.jsx b/src/main.jsx index 0136538..edb4375 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, getMqttUrl, getMqttCredentials } from "./config"; +import { getApiBase, getMqttUrl, getMqttCredentials, PARK_BOOTSTRAP_TOKEN } from "./config"; import { invoke } from "@tauri-apps/api/core"; import "./styles/global.css"; @@ -62,7 +62,10 @@ async function bootstrapRuntimeConfig() { // 则后端 /api/config 不再覆盖(避免后端默认 localhost 冲掉正确地址)。 const bakedMqtt = import.meta.env.VITE_MQTT_URL; try { - const res = await fetch(`${getApiBase()}/api/config`, { cache: 'no-store' }); + const res = await fetch(`${getApiBase()}/api/config`, { + cache: 'no-store', + headers: PARK_BOOTSTRAP_TOKEN ? { 'X-Park-Bootstrap': PARK_BOOTSTRAP_TOKEN } : undefined, + }); if (res.ok) { const cfg = await res.json(); if (!bakedMqtt && cfg.mqtt_url) window.__DPM_MQTT__ = cfg.mqtt_url; diff --git a/审查问题分布.html b/审查问题分布.html new file mode 100644 index 0000000..5dc55e7 --- /dev/null +++ b/审查问题分布.html @@ -0,0 +1,33 @@ + +