Skip to content

Commit

Permalink
Merge branch 'main' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
pgilmore-phi authored Oct 29, 2024
2 parents 6e820a0 + 60f83a3 commit 3d3d17c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scripts/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ function buildConfigURL(environment) {
return configURL;
}

function getValueFromData(configJSON, configParam) {
const configElements = JSON.parse(configJSON).data;
return configElements.find((c) => c.key === configParam)?.value;
}

/**
* @param {string} environment - leave empty to auto calculate the environment
* @returns - configuration (key,value) pairs of the environment as configured in configs.json
*/
export const getConfigForEnvironment = async (environment) => {
const env = (!environment) ? calcEnvironment() : environment;
let configJSON = window.sessionStorage.getItem(`config:${env}`);

if (configJSON) {
const foundPetUrl = getValueFromData(configJSON, 'found-pet-endpoint');
if (!foundPetUrl.includes('proxy')) {
configJSON = null;
}
}

if (!configJSON) {
const configURL = buildConfigURL(env);
const response = await fetch(configURL);
Expand Down

0 comments on commit 3d3d17c

Please sign in to comment.