Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Created March 2, 2018 08:24
Show Gist options
  • Save bjarneo/b739658abc65d78e394a860597dc4012 to your computer and use it in GitHub Desktop.
Save bjarneo/b739658abc65d78e394a860597dc4012 to your computer and use it in GitHub Desktop.
client side config
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),
};
@bjarneo
Copy link
Author

bjarneo commented Apr 13, 2021

Example default config:

// default.js

// module.exports = 
export default {
  api: 'https://www.nice-api.com/v1/cats',
  something: 'else',
  we: {
    like: {
      it: 'nested'
    }
  }
}

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