upda/server/web/src/getConfiguration.ts
Varakh d0312a5853
All checks were successful
/ build (push) Successful in 5m30s
feat(embedded_ui): fully integrate UI into GoLang binary (#43)
Reviewed-on: #43
Co-authored-by: Varakh <varakh@varakh.de>
Co-committed-by: Varakh <varakh@varakh.de>
2024-10-25 14:12:35 +00:00

29 lines
774 B
TypeScript

declare global {
interface Window {
runtime_config: Configuration;
}
}
interface Configuration {
VITE_API_URL: string;
VITE_APP_TITLE: string;
}
/**
* Derive configuration values depending on environment:
* - load from process.env in case of development
* - load from window object otherwise
*
* development check must be fully written as isDevelopment uses configuration itself
*/
const getConfiguration = (): Configuration => {
if (window && window.runtime_config && Object.keys(window.runtime_config).length > 0) {
return window.runtime_config;
} else if (import.meta.env.DEV) {
return import.meta.env as unknown as Configuration;
}
throw new Error('Cannot bootstrap configuration from window or environment');
};
export default getConfiguration;