fix(docker): harden frontend runtime config
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { backendBaseUrl as BASE } from "./runtime-config";
|
||||
import { backendBaseUrl as BASE, joinBackendPath } from "./runtime-config";
|
||||
|
||||
export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
// Only declare a JSON content-type when we actually send a body. Body-less
|
||||
@@ -10,7 +10,7 @@ export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T>
|
||||
if (init?.body != null && !("content-type" in headers) && !("Content-Type" in headers)) {
|
||||
headers["content-type"] = "application/json";
|
||||
}
|
||||
const res = await fetch(`${BASE}${path}`, { ...init, headers });
|
||||
const res = await fetch(joinBackendPath(BASE, path), { ...init, headers });
|
||||
if (!res.ok) throw new Error(`${res.status} ${await res.text().catch(() => "")}`);
|
||||
return res.status === 204 ? (undefined as T) : ((await res.json()) as T);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user