Skip to content

Instantly share code, notes, and snippets.

@DV8FromTheWorld
Last active March 3, 2021 21:42
Show Gist options
  • Save DV8FromTheWorld/9a671eed9efb7d52083c4b9b5097f848 to your computer and use it in GitHub Desktop.
Save DV8FromTheWorld/9a671eed9efb7d52083c4b9b5097f848 to your computer and use it in GitHub Desktop.
Inmar Environment Switch
(() => {
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);
})();
@DV8FromTheWorld
Copy link
Author

DV8FromTheWorld commented Dec 14, 2018

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:

  • Rebates [preprod, prod]
  • Eretail [dev, staging, prod]

environment-switch-example

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.

image

2) Copy the contents of the Inmar-Environment-Switch.js script

image

3) Find the bookmark, right-click on it, select edit...

image

4) Update the URL field with the contents of the script.

The format of this should be javascript: <pasted-code-here>

4a)

image

4b)

image

5) You can now switch between preprod and prod for both SPAs and API Swagger pages by clicking the bookmark button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment