Skip to content

Commit

Permalink
Merge pull request #699 from UKHSA-Internal/v3-development
Browse files Browse the repository at this point in the history
v3-development -> sandbox
  • Loading branch information
jaro-m authored Oct 11, 2023
2 parents c26ee41 + 5724221 commit 0d48510
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"lint": "yarn flow",
"start": "unset HOST && react-scripts start",
"build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build",
"postbuild": "node scripts/patchUrls.js",
"postbuild": "node scripts/patchUrls.js --max-old-space-size=3072",
"ppostbuild": "react-snap",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
32 changes: 31 additions & 1 deletion scripts/patchUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ const getFiles = (directory) => {
}; // getFiles


/**
* The function filters environment variables and returns only the important ones.
*
* @returns {object}
*/
const filterEnvVars = () => {
const vars = process.env;
const valid_keys = [
"BASE_URL",
"MAIN_CDN",
"DOWNLOADS_CDN",
"API_ENDPOINT",
"USER_API_ENDPOINT",
"APPINSIGHTS_INSTRUMENTATIONKEY"
]
const filteredVars = {}

Object.keys(vars).forEach(key => {
// Check if it can be one of the vars to use.
valid_keys.forEach(valid_key => {
if(vars.hasOwnProperty(key) && key.includes(valid_key)) {
filteredVars[key] = vars[key]
}
})
})

return filteredVars
}


/**
* Replaces placeholders formatted as `%key%` with environment
* variables defined using the same key.
Expand All @@ -94,7 +124,7 @@ const main = async () => {
files = getFiles(directory),
Replacements = {
...extractEnvVars(),
...process.env
...filterEnvVars()
};

for ( const file of files ) {
Expand Down

0 comments on commit 0d48510

Please sign in to comment.