From 2ad3b128d6ff1a3d551ed7e59b285dd6328fb9f0 Mon Sep 17 00:00:00 2001 From: Artem Reznichenko Date: Wed, 10 Jun 2026 13:49:38 +0300 Subject: [PATCH] fix: backend url normalization --- src/config/instances.ts | 7 ++++++- src/features/connect/ConnectPage.tsx | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config/instances.ts b/src/config/instances.ts index e768005..2bfd59e 100644 --- a/src/config/instances.ts +++ b/src/config/instances.ts @@ -29,8 +29,13 @@ const ACTIVE_KEY = 'mcma:activeInstance'; const LEGACY_URL_KEY = 'mcma_api_base_url'; const LEGACY_AUTH_KEY = 'mcma_auth'; +// The UI always talks to the `/api/v1` contract, so users only enter the +// origin (and optional reverse-proxy prefix). We append the contract path +// here, the single choke point for both the base URL and the instance id, so +// `domain.com`, `domain.com/`, and `domain.com/api/v1` all converge. function normalizeUrl(url: string): string { - return url.trim().replace(/\/+$/, ''); + const trimmed = url.trim().replace(/\/+$/, ''); + return /\/api\/v1$/.test(trimmed) ? trimmed : `${trimmed}/api/v1`; } /** Stable, readable id from a base URL — also serves as the storage namespace. */ diff --git a/src/features/connect/ConnectPage.tsx b/src/features/connect/ConnectPage.tsx index f9b2459..13d2ef2 100644 --- a/src/features/connect/ConnectPage.tsx +++ b/src/features/connect/ConnectPage.tsx @@ -213,7 +213,7 @@ export function ConnectPage() { setApiUrl(e.target.value)} - placeholder="https://your-server.example.com/api/v1" + placeholder="https://your-server.example.com" required />