Skip to content

Commit c800477

Browse files
authored
📚 using Runtime Configuration from create-react-app-buildpack
1 parent b65b1b2 commit c800477

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
A minimal example of using a Node backend (server for API, proxy, & routing) with a [React frontend](https://github.com/facebookincubator/create-react-app).
44

5+
* 📐 [Design Points](#user-content-design-points)
6+
* 🕺 [Demo](#user-content-demo)
7+
* 🚀 [Deploy to Heroku](#user-content-deploy-to-heroku)
8+
* ⤵️ [Switching from create-react-app-buildpack](#user-content-switching-from-create-react-app-buildpack)
9+
* 🎛 [Runtime Config](#user-content-runtime-config)
10+
* 💻 [Local Development](#user-content-local-development)
11+
512
To deploy a frontend-only React app, use the static-site optimized
613
▶️ [create-react-app-buildpack](https://github.com/mars/create-react-app-buildpack)
714

8-
⤵️ [Switching from create-react-app-buildpack](#switching-from-create-react-app-buildpack)?
9-
1015

1116
## Design Points
1217

@@ -78,7 +83,33 @@ If an app was previously deployed with [create-react-app-buildpack](https://gith
7883
git commit -m 'Migrate from create-react-app-buildpack to Node server'
7984
git push heroku master
8085
```
81-
86+
1. If the app uses [Runtime configuration](https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-runtime-configuration), then follow [Runtime config](#user-content-runtime-config) below to keep it working.
87+
88+
## Runtime Config
89+
90+
create-react-app itself supports [configuration with environment variables](https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables). These compile-time variables are embedded in the bundle during the build process, and may go stale when the app slug is promoted through a pipeline or otherwise changed without a rebuild. See create-react-app-buildpack's docs for further elaboration of [compile-time vs runtime variables](https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-compile-time-vs-runtime).
91+
92+
[create-react-app-buildpack's runtime config](https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-runtime-configuration) makes it possible to dynamically change variables, no rebuild required. That runtime config technique may be applied to Node.js based apps such as this one.
93+
94+
1. Add the inner buildpack to your app, so that the `heroku/nodejs` buildpack is last:
95+
96+
```bash
97+
heroku buildpacks:add -i 1 https://github.com/mars/create-react-app-inner-buildpack
98+
99+
# Verify that create-react-app-inner-buildpack comes before nodejs
100+
heroku buildpacks
101+
```
102+
2. Set the bundle location for runtime config injection:
103+
104+
```bash
105+
heroku config:set JS_RUNTIME_TARGET_BUNDLE=/app/react-ui/build/static/js/*.js
106+
```
107+
3. Now, build the app with this new setup:
108+
109+
```bash
110+
git commit --allow-empty -m 'Enable runtime config with create-react-app-inner-buildpack'
111+
git push heroku master
112+
```
82113

83114
## Local Development
84115

0 commit comments

Comments
 (0)