Varakh
d0312a5853
All checks were successful
/ build (push) Successful in 5m30s
Reviewed-on: #43 Co-authored-by: Varakh <varakh@varakh.de> Co-committed-by: Varakh <varakh@varakh.de>
29 lines
774 B
TypeScript
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;
|