Runtime Client-Side Configuration
Sample project demonstrating how to access configuration and environment variables in browser on runtime.
- Navigate to root directory.
npm run build
This is built with
- Ubuntu 18.0.4
- Node v10.9.0
- npm 6.7.0
I suppose it would work on similar unix-like setups too.
The source code is split into two subfolders,
server, each having its own
The server entry point is located in
server/src/srver.js and it calls two more modules,
The app is created with create-react-app. There are only a few changes to this basic client application.
- A new file
runtimeConfig.jsis added. It loads and stores the configuration variables.
index.jsis the entry point and it calls the runtime configuration
loadfunction as soon as possible.
- The values are displayed in
App.jscomponent. They are fetched on
componentDidMountand displayed as soon as they are available.