diff --git a/src/core/configuration/ConfigLoader.ts b/src/core/configuration/ConfigLoader.ts index 4987da1c3..82e5f66b5 100644 --- a/src/core/configuration/ConfigLoader.ts +++ b/src/core/configuration/ConfigLoader.ts @@ -9,14 +9,6 @@ import { prodConfig } from "./ProdConfig"; export let cachedSC: ServerConfig | null = null; -declare global { - interface Window { - BOOTSTRAP_CONFIG?: { - gameEnv?: string; - }; - } -} - export async function getConfig( gameConfig: GameConfig, userSettings: UserSettings | null, @@ -39,12 +31,13 @@ export async function getServerConfigFromClient(): Promise { return cachedSC; } - const bootstrapGameEnv = window.BOOTSTRAP_CONFIG?.gameEnv; - if (!bootstrapGameEnv) { - throw new Error("Missing bootstrap server config"); + // Vite replaces this in browser and worker bundles at build time. + const gameEnv = process.env.GAME_ENV; + if (!gameEnv) { + throw new Error("Missing client server config"); } - cachedSC = getServerConfig(bootstrapGameEnv); + cachedSC = getServerConfig(gameEnv); return cachedSC; } export function getServerConfigFromServer(): ServerConfig { diff --git a/tests/core/configuration/ConfigLoader.test.ts b/tests/core/configuration/ConfigLoader.test.ts index 65fd81757..6bf14163e 100644 --- a/tests/core/configuration/ConfigLoader.test.ts +++ b/tests/core/configuration/ConfigLoader.test.ts @@ -6,14 +6,16 @@ import { } from "../../../src/core/configuration/ConfigLoader"; describe("ConfigLoader", () => { + const originalGameEnv = process.env.GAME_ENV; + beforeEach(() => { vi.restoreAllMocks(); - window.BOOTSTRAP_CONFIG = undefined; + process.env.GAME_ENV = originalGameEnv; clearCachedServerConfig(); }); - test("uses bootstrap config without fetching /api/env", async () => { - window.BOOTSTRAP_CONFIG = { gameEnv: "prod" }; + test("uses bundled GAME_ENV without fetching /api/env", async () => { + process.env.GAME_ENV = "prod"; const fetchSpy = vi.spyOn(globalThis, "fetch"); const config = await getServerConfigFromClient();