fix(desktop): normalize API base URL across renderer and main

Replace ad-hoc trim/fallback logic with a shared normalizer that strips
trailing slashes and accidental /api suffixes, rejects non-http schemes,
and rewrites Vite dev origins (517x) back to localhost:8080 so the
desktop client never points its API client at the renderer dev server.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 12:56:47 +08:00
parent 7b4d7ccf68
commit 13464c7788
4 changed files with 71 additions and 10 deletions
@@ -22,6 +22,7 @@ import {
normalizeAccountPlatformUid,
sameAccountPlatformUid,
} from '../shared/account-identity'
import { normalizeDesktopApiBaseURL } from '../shared/api-base-url'
import { type PublishAccountIdentity, type PublishAccountProfile } from './account-binder'
import {
ensureAccountReady,
@@ -3267,7 +3268,7 @@ function normalizeSession(
}
return {
api_base_url: session.api_base_url.trim() || 'http://localhost:8080',
api_base_url: normalizeDesktopApiBaseURL(session.api_base_url),
mode: session.mode,
client_token: session.client_token?.trim() || null,
desktop_client: session.desktop_client ? { ...session.desktop_client } : null,