build(docker): add runtime-configured frontend image
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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";
|
||||
Reference in New Issue
Block a user