2023-04-24 17:41:54 +02:00
|
|
|
import { APP_VERSION, DISCORD_LINK, GITHUB_LINK } from "./constants";
|
2022-12-27 16:44:36 +01:00
|
|
|
|
2022-12-29 18:25:57 +01:00
|
|
|
interface Config {
|
2022-12-27 16:44:36 +01:00
|
|
|
APP_VERSION: string;
|
|
|
|
GITHUB_LINK: string;
|
|
|
|
DISCORD_LINK: string;
|
2023-06-23 21:58:33 +02:00
|
|
|
TMDB_READ_API_KEY: string;
|
2022-12-27 16:44:36 +01:00
|
|
|
CORS_PROXY_URL: string;
|
2023-02-19 16:05:19 +01:00
|
|
|
NORMAL_ROUTER: boolean;
|
2023-10-31 21:08:09 +01:00
|
|
|
BACKEND_URL: string;
|
2022-12-27 16:44:36 +01:00
|
|
|
}
|
|
|
|
|
2023-02-22 21:41:13 +01:00
|
|
|
export interface RuntimeConfig {
|
|
|
|
APP_VERSION: string;
|
|
|
|
GITHUB_LINK: string;
|
|
|
|
DISCORD_LINK: string;
|
2023-06-23 21:58:33 +02:00
|
|
|
TMDB_READ_API_KEY: string;
|
2023-02-22 21:41:13 +01:00
|
|
|
NORMAL_ROUTER: boolean;
|
|
|
|
PROXY_URLS: string[];
|
2023-10-31 21:08:09 +01:00
|
|
|
BACKEND_URL: string;
|
2022-12-29 18:25:57 +01:00
|
|
|
}
|
|
|
|
|
2022-12-27 16:44:36 +01:00
|
|
|
const env: Record<keyof Config, undefined | string> = {
|
2023-06-23 21:58:33 +02:00
|
|
|
TMDB_READ_API_KEY: import.meta.env.VITE_TMDB_READ_API_KEY,
|
2022-12-27 16:44:36 +01:00
|
|
|
APP_VERSION: undefined,
|
|
|
|
GITHUB_LINK: undefined,
|
|
|
|
DISCORD_LINK: undefined,
|
|
|
|
CORS_PROXY_URL: import.meta.env.VITE_CORS_PROXY_URL,
|
2023-02-19 16:05:19 +01:00
|
|
|
NORMAL_ROUTER: import.meta.env.VITE_NORMAL_ROUTER,
|
2023-10-31 21:08:09 +01:00
|
|
|
BACKEND_URL: import.meta.env.VITE_BACKEND_URL,
|
2022-12-27 16:44:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// loads from different locations, in order: environment (VITE_{KEY}), window (public/config.js)
|
2023-06-23 21:58:33 +02:00
|
|
|
function getKeyValue(key: keyof Config): string | undefined {
|
2022-12-27 16:44:36 +01:00
|
|
|
let windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`];
|
|
|
|
if (windowValue !== undefined && windowValue.length === 0)
|
|
|
|
windowValue = undefined;
|
2023-06-23 21:58:33 +02:00
|
|
|
return env[key] ?? windowValue ?? undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getKey(key: keyof Config, defaultString?: string): string {
|
|
|
|
return getKeyValue(key) ?? defaultString ?? "";
|
|
|
|
}
|
2022-12-27 16:44:36 +01:00
|
|
|
|
2022-12-29 18:25:57 +01:00
|
|
|
export function conf(): RuntimeConfig {
|
2022-12-27 16:44:36 +01:00
|
|
|
return {
|
|
|
|
APP_VERSION,
|
|
|
|
GITHUB_LINK,
|
|
|
|
DISCORD_LINK,
|
2023-10-31 21:08:09 +01:00
|
|
|
BACKEND_URL: getKey("BACKEND_URL"),
|
2023-06-23 21:58:33 +02:00
|
|
|
TMDB_READ_API_KEY: getKey("TMDB_READ_API_KEY"),
|
2023-02-22 21:41:13 +01:00
|
|
|
PROXY_URLS: getKey("CORS_PROXY_URL")
|
|
|
|
.split(",")
|
|
|
|
.map((v) => v.trim()),
|
2023-02-22 21:54:02 +01:00
|
|
|
NORMAL_ROUTER: getKey("NORMAL_ROUTER", "false") === "true",
|
2022-12-27 16:44:36 +01:00
|
|
|
};
|
|
|
|
}
|