Last active
March 3, 2021 21:42
-
-
Save DV8FromTheWorld/9a671eed9efb7d52083c4b9b5097f848 to your computer and use it in GitHub Desktop.
Inmar Environment Switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const envMap = [ | |
['preprod.aws-nonprod', 'prod.aws-prod'], | |
['prod.aws-prod', 'preprod.aws-nonprod'], | |
['dev.eretail-dev', ['staging.eretail-dev', 'prod.eretail']], | |
['staging.eretail-dev', ['dev.eretail-dev', 'prod.eretail']], | |
['prod.eretail', ['dev.eretail-dev', 'staging.eretail-dev']], | |
['dev.inmartgrocery.com', ['staging.inmartgrocery.com', 'inmartgrocery.com']], | |
['staging.inmartgrocery.com', ['dev.inmartgrocery.com', 'inmartgrocery.com']], | |
['inmartgrocery.com', ['dev.inmartgrocery.com', 'staging.inmartgrocery.com']] | |
]; | |
const pick = (options) => { | |
const decision = prompt(`Please choose an option. You don't need to type the entire option.\n ${options.join('\n ')}`); | |
if (decision === null) { | |
return null; | |
} | |
if (!decision.length) { | |
return pick(options); | |
} | |
const chosenOption = options.find(option => option.startsWith(decision)); | |
if (!chosenOption) { | |
return pick(options); | |
} | |
return chosenOption; | |
}; | |
const envMatch = envMap.filter(([currentFQDN]) => location.href.includes(currentFQDN))[0]; | |
if (!envMatch) { | |
alert("Current page is not a recognized environment-aware inmar page"); | |
} | |
let nextFQDN = null; | |
const [currentFQDN, nextFQDNOptions] = envMatch; | |
if (Array.isArray(nextFQDNOptions)) { | |
nextFQDN = pick(nextFQDNOptions); | |
if (!nextFQDN) { | |
return; | |
} | |
} | |
else { | |
nextFQDN = nextFQDNOptions; | |
} | |
location = location.href.replace(currentFQDN, nextFQDN); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist provides a simple way to setup a bookmark that can be used to easily switch between preprod and prod for SPAs and Swagger pages.
Supports:
Install
To properly use this, bookmark this current page and replace the url with the javascript above.
In chrome it looks like the following:
1) Bookmark this gist. Note, I put it in my
Inmar
folder to find it easier.2) Copy the contents of the
Inmar-Environment-Switch.js
script3) Find the bookmark, right-click on it, select
edit...
4) Update the
URL
field with the contents of the script.The format of this should be
javascript: <pasted-code-here>
4a)
4b)
5) You can now switch between
preprod
andprod
for both SPAs and API Swagger pages by clicking the bookmark button.