fix loading env config

This commit is contained in:
Lukas Hass 2022-02-01 00:34:18 +01:00
parent b1e9969ed8
commit 1b41e794da
No known key found for this signature in database
GPG Key ID: 7C8CEF72C4039178

View File

@ -1,46 +1,48 @@
declare global { // import { getEnvConfig } from "@geprog/vite-plugin-env-config";
interface Window {
env?: Record<string, string>; interface EnvConfig {
} [key: string]: string;
} }
const getEnv = (key: string): string | undefined => { function getEnvConfig<T extends keyof EnvConfig>(key: keyof EnvConfig): EnvConfig[T] | undefined {
if (global.window?.env) { const _window = globalThis.window as unknown as { env?: EnvConfig };
return global.window.env[key]; if (_window?.env) {
return _window.env[key];
} }
if (global.process?.env) { if (globalThis.process?.env) {
return global.process.env[key]; return globalThis.process.env[key];
} }
return; return;
}; }
const DEBUG_MODE: boolean = getEnv("DEBUG_MODE") == "true"; const DEBUG_MODE: boolean = getEnvConfig("DEBUG_MODE") == "true";
const START_ROOM_URL: string = getEnv("START_ROOM_URL") || "/_/global/maps.workadventure.localhost/Floor1/floor1.json"; const START_ROOM_URL: string =
const PUSHER_URL = getEnv("PUSHER_URL") || "//pusher.workadventure.localhost"; getEnvConfig("START_ROOM_URL") || "/_/global/maps.workadventure.localhost/Floor1/floor1.json";
export const ADMIN_URL = getEnv("ADMIN_URL") || "//workadventu.re"; const PUSHER_URL = getEnvConfig("PUSHER_URL") || "//pusher.workadventure.localhost";
const UPLOADER_URL = getEnv("UPLOADER_URL") || "//uploader.workadventure.localhost"; export const ADMIN_URL = getEnvConfig("ADMIN_URL") || "//workadventu.re";
const ICON_URL = getEnv("ICON_URL") || "//icon.workadventure.localhost"; const UPLOADER_URL = getEnvConfig("UPLOADER_URL") || "//uploader.workadventure.localhost";
const STUN_SERVER: string = getEnv("STUN_SERVER") || "stun:stun.l.google.com:19302"; const ICON_URL = getEnvConfig("ICON_URL") || "//icon.workadventure.localhost";
const TURN_SERVER: string = getEnv("TURN_SERVER") || ""; const STUN_SERVER: string = getEnvConfig("STUN_SERVER") || "stun:stun.l.google.com:19302";
const SKIP_RENDER_OPTIMIZATIONS: boolean = getEnv("SKIP_RENDER_OPTIMIZATIONS") == "true"; const TURN_SERVER: string = getEnvConfig("TURN_SERVER") || "";
const DISABLE_NOTIFICATIONS: boolean = getEnv("DISABLE_NOTIFICATIONS") == "true"; const SKIP_RENDER_OPTIMIZATIONS: boolean = getEnvConfig("SKIP_RENDER_OPTIMIZATIONS") == "true";
const TURN_USER: string = getEnv("TURN_USER") || ""; const DISABLE_NOTIFICATIONS: boolean = getEnvConfig("DISABLE_NOTIFICATIONS") == "true";
const TURN_PASSWORD: string = getEnv("TURN_PASSWORD") || ""; const TURN_USER: string = getEnvConfig("TURN_USER") || "";
const JITSI_URL: string | undefined = getEnv("JITSI_URL") === "" ? undefined : getEnv("JITSI_URL"); const TURN_PASSWORD: string = getEnvConfig("TURN_PASSWORD") || "";
const JITSI_PRIVATE_MODE: boolean = getEnv("JITSI_PRIVATE_MODE") == "true"; const JITSI_URL: string | undefined = getEnvConfig("JITSI_URL") === "" ? undefined : getEnvConfig("JITSI_URL");
const JITSI_PRIVATE_MODE: boolean = getEnvConfig("JITSI_PRIVATE_MODE") == "true";
const POSITION_DELAY = 200; // Wait 200ms between sending position events const POSITION_DELAY = 200; // Wait 200ms between sending position events
const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new movement is sent by the player const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new movement is sent by the player
export const MAX_USERNAME_LENGTH = parseInt(getEnv("MAX_USERNAME_LENGTH") || "") || 8; export const MAX_USERNAME_LENGTH = parseInt(getEnvConfig("MAX_USERNAME_LENGTH") || "") || 8;
export const MAX_PER_GROUP = parseInt(getEnv("MAX_PER_GROUP") || "4"); export const MAX_PER_GROUP = parseInt(getEnvConfig("MAX_PER_GROUP") || "4");
export const DISPLAY_TERMS_OF_USE = getEnv("DISPLAY_TERMS_OF_USE") == "true"; export const DISPLAY_TERMS_OF_USE = getEnvConfig("DISPLAY_TERMS_OF_USE") == "true";
export const NODE_ENV = getEnv("NODE_ENV") || "development"; export const NODE_ENV = getEnvConfig("NODE_ENV") || "development";
export const CONTACT_URL = getEnv("CONTACT_URL") || undefined; export const CONTACT_URL = getEnvConfig("CONTACT_URL") || undefined;
export const PROFILE_URL = getEnv("PROFILE_URL") || undefined; export const PROFILE_URL = getEnvConfig("PROFILE_URL") || undefined;
export const POSTHOG_API_KEY: string = (getEnv("POSTHOG_API_KEY") as string) || ""; export const POSTHOG_API_KEY: string = (getEnvConfig("POSTHOG_API_KEY") as string) || "";
export const POSTHOG_URL = getEnv("POSTHOG_URL") || undefined; export const POSTHOG_URL = getEnvConfig("POSTHOG_URL") || undefined;
export const DISABLE_ANONYMOUS: boolean = getEnv("DISABLE_ANONYMOUS") === "true"; export const DISABLE_ANONYMOUS: boolean = getEnvConfig("DISABLE_ANONYMOUS") === "true";
export const OPID_LOGIN_SCREEN_PROVIDER = getEnv("OPID_LOGIN_SCREEN_PROVIDER"); export const OPID_LOGIN_SCREEN_PROVIDER = getEnvConfig("OPID_LOGIN_SCREEN_PROVIDER");
const FALLBACK_LOCALE = getEnv("FALLBACK_LOCALE") || undefined; const FALLBACK_LOCALE = getEnvConfig("FALLBACK_LOCALE") || undefined;
export { export {
DEBUG_MODE, DEBUG_MODE,