gothinkster / react-redux-realworld-example-app

Exemplary real world application built with React + Redux
https://react-redux.realworld.io
MIT License
5.55k stars 2.5k forks source link

Override the `API_ROOT` in production builds using environment variables #107

Open simbo1905 opened 6 years ago

simbo1905 commented 6 years ago

The readme says to edit the src/agent.js to change the API_ROOT to point to a different backend api instance. We want to set things up so that API_ROOT can be defined by an environment variable that is different for the multiple environments(e.g., “staging” and “live”) where we run the production build.

We are running in containers on openshift kubernetes following 12factor.net principles where the code is built once then promoted through environments. We can spin up new new environments with a single command so we don’t want to have a switch statement within the code that names each environment and hardcodes the backend API_ROOT for each environment. Instead I want to be able to run an existing production build container image in a fresh environment where I have change the API_ROOT to point to the correct backend API that has the data we want to test against.

I have asked about the best way to do this on stackoverflow.com at https://stackoverflow.com/q/49975735/329496