fix: 前端 WebSocket URL 改为环境变量或自动推导,消除 localhost 硬编码

This commit is contained in:
hhs
2026-06-14 11:55:07 +08:00
parent 22aefbc216
commit 4a7cf89f29

View File

@@ -6,7 +6,10 @@
import type { ClientMessage, ServerMessage, WsMessage } from "../types";
const WS_URL = "ws://localhost:8080/ws";
// WebSocket 地址:优先使用环境变量,否则基于当前页面地址自动推导
const WS_URL =
import.meta.env.VITE_WS_URL ||
`${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}/ws`;
const PING_INTERVAL = 30_000; // 30 秒心跳
const MAX_RECONNECT_DELAY = 30_000; // 最大重连延迟 30 秒