diff --git a/frontend/src/api/config.js b/frontend/src/api/config.js index 7673e3c..f2e645c 100644 --- a/frontend/src/api/config.js +++ b/frontend/src/api/config.js @@ -1 +1,20 @@ -export const API_BASE = import.meta.env.VITE_API_BASE || "/v1"; +const DEFAULT_API_BASE = "/v1"; + +/** + * API origin for fetch(): root-relative prefix (e.g. /v1) or absolute URL (https://host/v1). + * Root-relative values are forced to start with "/" so requests work from any SPA route + * (e.g. /support); otherwise "v1/support" would resolve under the current path and 404. + */ +function normalizeApiBase(raw) { + const s = String(raw ?? "").trim(); + const base = s || DEFAULT_API_BASE; + + if (/^https?:\/\//i.test(base)) { + return base.replace(/\/+$/, "") || DEFAULT_API_BASE; + } + + const path = base.startsWith("/") ? base : `/${base}`; + return path.replace(/\/+$/, "") || DEFAULT_API_BASE; +} + +export const API_BASE = normalizeApiBase(import.meta.env.VITE_API_BASE); diff --git a/frontend/src/api/support.js b/frontend/src/api/support.js index cfe03e7..fc40f6f 100644 --- a/frontend/src/api/support.js +++ b/frontend/src/api/support.js @@ -15,7 +15,7 @@ export async function submitSupportRequest({ email, description }) { if (data.message) message = data.message; else if (data.error && res.status) message = `${data.error} (${res.status})`; } catch { - message = `Request failed (${res.status}). Is the API running on port 3001?`; + message = `Request failed (HTTP ${res.status}). The server did not return JSON — check that POST ${API_BASE}/support is proxied to your Go API (e.g. nginx location /v1/).`; } throw new Error(message); }