Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/components/settings/DebugSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions src/services/wsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

// ============================================================================
Expand Down
13 changes: 9 additions & 4 deletions src/utils/backendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading