From d24b9d4495d9047b78377ad8661823153a18204c Mon Sep 17 00:00:00 2001 From: "Mark J. Becker" Date: Wed, 5 Jun 2024 12:02:12 +0200 Subject: [PATCH] Split config files --- scripts/configs.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/configs.js b/scripts/configs.js index d56331a15c..f3f79daedd 100644 --- a/scripts/configs.js +++ b/scripts/configs.js @@ -1,3 +1,5 @@ +const ALLOWED_CONFIGS = ['prod', 'stage', 'dev']; + /** * This function calculates the environment in which the site is running based on the URL. * It defaults to 'prod'. In non 'prod' environments, the value can be overwritten using @@ -16,7 +18,7 @@ export const calcEnvironment = () => { } const environmentFromConfig = window.sessionStorage.getItem('environment'); - if (environmentFromConfig && environment !== 'prod') { + if (environmentFromConfig && ALLOWED_CONFIGS.includes(environmentFromConfig) && environment !== 'prod') { return environmentFromConfig; } @@ -25,8 +27,11 @@ export const calcEnvironment = () => { function buildConfigURL(environment) { const env = environment || calcEnvironment(); - const configURL = new URL(`${window.location.origin}/configs.json`); - configURL.searchParams.set('sheet', env); + let fileName = 'configs.json?sheet=prod'; + if (env !== 'prod') { + fileName = `configs-${env}.json`; + } + const configURL = new URL(`${window.location.origin}/${fileName}`); return configURL; }