feat: 添加后端部署和API基本检索的Docker Compose配置
- 引入新的`docker-compose.yml`文件,便于后端和MQTT代理(EMQX)的部署。 - 更新多个组件中的API基本检索,使用函数进行动态解析。 - 加强了多个组件中API调用的错误处理和日志记录。 - 优化了AI聊天面板离线场景的回退响应。 - 更新DataScreen和MediaScreen组件中的数据显示和统计,以反映准确的指标。 - 重构MQTT连接逻辑,以支持动态凭证和客户端ID。
This commit is contained in:
+33
-7
@@ -2,12 +2,38 @@ import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import { ThemeProvider } from "@appica/ui-react/providers/theme-provider";
|
||||
import { API_BASE } from "./config";
|
||||
import "./styles/global.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
<React.StrictMode>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
/* =========================================================
|
||||
启动引导(打包部署关键):
|
||||
渲染前先从后端 GET /api/config 拉取运行时配置
|
||||
(MQTT 地址/账号、API 基址),写入 window.__DPM_*__,
|
||||
之后 api.js / mqtt.js 均以惰性读取方式生效。
|
||||
后端不可达时静默使用内置默认(Tauri 打包回退 127.0.0.1)。
|
||||
========================================================= */
|
||||
async function bootstrapRuntimeConfig() {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE()}/api/config`, { cache: 'no-store' });
|
||||
if (!res.ok) return;
|
||||
const cfg = await res.json();
|
||||
// 仅覆盖 MQTT 连接信息(后端 .env 为准);API 基址以前端实际可达地址为准
|
||||
if (cfg.mqtt_url) window.__DPM_MQTT__ = cfg.mqtt_url;
|
||||
if (cfg.mqtt_username) window.__DPM_MQTT_USER__ = cfg.mqtt_username;
|
||||
if (cfg.mqtt_password) window.__DPM_MQTT_PASS__ = cfg.mqtt_password;
|
||||
// eslint-disable-next-line no-console
|
||||
if (cfg.mqtt_url) console.info(`[bootstrap] MQTT -> ${cfg.mqtt_url}`);
|
||||
} catch {
|
||||
/* 后端不可达:使用内置默认地址 */
|
||||
}
|
||||
}
|
||||
|
||||
bootstrapRuntimeConfig().then(() => {
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
<React.StrictMode>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user