From 101ffd415f1f38cb3cc11af9a020c8440c29483b Mon Sep 17 00:00:00 2001 From: Jingbo Zhai Date: Mon, 29 Jun 2026 14:43:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=97=B6webui=20wss=E6=97=A0=E6=B3=95=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=88=B0=E6=AD=A3=E7=A1=AE=E7=9A=84=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/wsService.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/services/wsService.ts b/src/services/wsService.ts index fd4168e1..5588cf14 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -91,12 +91,16 @@ export function setServerPort(port: number): void { function getWsUrl(): string { const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - if (serverPort) { - const hostname = window.location.hostname; - return `${protocol}//${hostname}:${serverPort}/api/ws`; + + // 正常情况:通过 Nginx 反向代理 + if (window.location.host) { + return `${protocol}//${window.location.host}/api/ws`; } - const host = window.location.host; - return `${protocol}//${host}/api/ws`; + + // Fallback:直连后端 + const hostname = window.location.hostname || '127.0.0.1'; + const port = serverPort || 12701; + return `${protocol}//${hostname}:${port}/api/ws`; } // ============================================================================ From 48b2365e69263c49987b589d7636a6624197d82b Mon Sep 17 00:00:00 2001 From: Jingbo Zhai Date: Mon, 29 Jun 2026 15:18:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=97=B6url=E5=A4=84=E7=90=86=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/settings/DebugSection.tsx | 22 ++++++++++++++-------- src/utils/backendApi.ts | 13 +++++++++---- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/components/settings/DebugSection.tsx b/src/components/settings/DebugSection.tsx index 2e0ac203..c923cbca 100644 --- a/src/components/settings/DebugSection.tsx +++ b/src/components/settings/DebugSection.tsx @@ -139,14 +139,20 @@ export function DebugSection() { } }; - const webServerAddress = (() => { - if (!webServerPort) return null; - if (allowLanAccess) { - const host = isTauri() ? lanIp || 'localhost' : window.location.hostname; - return `http://${host}:${webServerPort}`; - } - return `http://localhost:${webServerPort}`; - })(); +const webServerAddress = (() => { + + if (window.location.host && !isTauri()) { + return window.location.origin; + } + + // Tauri 桌面端直连后端 + if (!webServerPort) return null; + + const host = allowLanAccess + ? (lanIp || 'localhost') + : 'localhost'; + return `http://${host}:${webServerPort}`; +})(); const handleOpenWebServer = useCallback(async () => { if (!webServerAddress) return; diff --git a/src/utils/backendApi.ts b/src/utils/backendApi.ts index 80c58e35..077d6a83 100644 --- a/src/utils/backendApi.ts +++ b/src/utils/backendApi.ts @@ -16,11 +16,16 @@ export function setBackendPort(port: number): void { } export function getApiBase(): string { - if (backendPort) { - const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:'; - return `${protocol}//${window.location.hostname}:${backendPort}/api`; + // 正常情况:通过 Nginx 反向代理,用相对路径 + if (window.location.host) { + return '/api'; } - return '/api'; + + // Fallback:直连后端 + const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:'; + const hostname = window.location.hostname || '127.0.0.1'; + const port = backendPort || 12701; + return `${protocol}//${hostname}:${port}/api`; } /** 安全解析 JSON 响应,204 / 空 body 时返回 undefined */