mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 07:40:43 +00:00
Use bundled GAME_ENV for client config
This commit is contained in:
@@ -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<ServerConfig> {
|
||||
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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user