Created
March 2, 2018 08:24
-
-
Save bjarneo/b739658abc65d78e394a860597dc4012 to your computer and use it in GitHub Desktop.
client side config
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
import merge from 'deepmerge'; | |
import delve from 'dlv'; | |
import defaultConfig from './default'; | |
const { REACT_APP_ENV, NODE_ENV } = process.env; | |
const ENV = REACT_APP_ENV || NODE_ENV; | |
const config = () => { | |
try { | |
return merge(defaultConfig, require(`./${ENV}.js`).default); | |
} catch (e) { | |
console.log(` CONFIG: Environment "${ENV}" not found.`); | |
return defaultConfig; | |
} | |
}; | |
// https://github.com/developit/dlv | |
// config.get('my.nested.config', 'defaultValue') | |
export default { | |
get: (value, def = '') => delve(config(), value, def), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example default config: