build(docker): add runtime-configured frontend image

This commit is contained in:
2026-07-11 21:57:53 +02:00
parent 31023f9e7a
commit 3d939426b1
9 changed files with 150 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
const BASE = import.meta.env.VITE_BACKEND_URL ?? "http://localhost:8787";
import { backendBaseUrl as BASE } 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
+17
View File
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";
import { backendBaseUrl, resolveBackendUrl } from "./runtime-config";
describe("resolveBackendUrl", () => {
it("uses the runtime-injected backend URL", () => {
expect(resolveBackendUrl({ backendBaseUrl: "/api" })).toBe("/api");
});
it("falls back to the Vite backend URL", () => {
expect(resolveBackendUrl(undefined)).toBe(import.meta.env.VITE_BACKEND_URL ?? "");
});
it("preserves the client default when Vite has no configured backend", () => {
expect(backendBaseUrl).toBe(import.meta.env.VITE_BACKEND_URL ?? "http://localhost:8787");
});
});
+17
View File
@@ -0,0 +1,17 @@
export interface RuntimeConfig {
backendBaseUrl?: string;
}
declare global {
interface Window {
__THOTHII_CONFIG__?: RuntimeConfig;
}
}
export function resolveBackendUrl(config: RuntimeConfig | undefined): string {
return config?.backendBaseUrl ?? import.meta.env.VITE_BACKEND_URL ?? "";
}
export const backendBaseUrl =
resolveBackendUrl(typeof window === "undefined" ? undefined : window.__THOTHII_CONFIG__) ||
"http://localhost:8787";