Skip to content

Instantly share code, notes, and snippets.

@keyserfaty
Last active March 22, 2017 13:37
Show Gist options
  • Save keyserfaty/76ed80a52561315d9094e9c38b81961e to your computer and use it in GitHub Desktop.
Save keyserfaty/76ed80a52561315d9094e9c38b81961e to your computer and use it in GitHub Desktop.
Setting different environments in FE
// defaults/index.js
import development from './development';
import production from './production';
export default {
development,
production
}[process.env.NODE_ENV || 'development'];
// defaults/development.js
export default {
url: 'http://localhost:8000'
};
// defaults/production.js
export default {
url: 'http://produrl.com'
};
// package.json
{
"scripts": {
"start:prod": "NODE_ENV=production node app.js",
"start": "NODE_ENV=development react-scripts start"
}
}
// usage in a file:
import api from '../defaults'
const getUrl = () => api.url // this should be localhost or produrl.com according to environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment