Merge pull request #43 from kjannette/adjust-url-support-form-submit
Adjust endpoint
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user