Skip to content

Commit

Permalink
Split config files
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 committed Jun 5, 2024
1 parent d59bbce commit d24b9d4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/configs.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit d24b9d4

Please sign in to comment.