diff --git a/src/utils/api.ts b/src/utils/api.ts index 1c57d5f..fcb9a2f 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -30,15 +30,16 @@ export async function apiJson(path: string, init?: RequestInit): Promise { } function normalizeLoopbackHost(rawUrl: string): string { + const cleaned = rawUrl.trim().replace(/^['"`\s]+|['"`\s]+$/g, ""); try { - const url = new URL(rawUrl, window.location.origin); + const url = new URL(cleaned, window.location.origin); const loopbacks = new Set(["127.0.0.1", "localhost", "::1"]); if (loopbacks.has(url.hostname) && !loopbacks.has(window.location.hostname)) { url.hostname = window.location.hostname; } return url.toString().replace(/\/+$/, ""); } catch { - return rawUrl.replace(/\/+$/, ""); + return cleaned.replace(/\/+$/, ""); } }