Created
August 4, 2020 23:32
-
-
Save 0ex-d/e48d73b342c625a5704ab16167266c02 to your computer and use it in GitHub Desktop.
React Javascript environment config for various URL rules. Used in my React Native project.
This file contains 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
/* | |
* Configure various url rules per environment | |
* Use `envSelector` and createSelector hooks to load env.json file | |
* By Precious Akin | |
*/ | |
import { createSelector } from 'reselect'; | |
import ENV_FILE from '../../env.json'; | |
const envSelector = () => ENV_FILE; | |
export const apiURL = createSelector( | |
envSelector, | |
ENV => { | |
switch (ENV.network) { | |
case 'dev': | |
return `http://${ENV.offline_host || '0.0.0.0'}:9100` | |
case 'staging': | |
return '' | |
case 'production': | |
return 'https://prod-app.com' | |
default: | |
return 'https://staging-app.com' | |
} | |
} | |
); |
Call function in axios or fetch
let health_link = await axios.get(
${apiURL}/health);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the json schema
{
"network": "production",
"offline_host": "127.0.0.1",
}