|
2 | 2 |
|
3 | 3 | A minimal example of using a Node backend (server for API, proxy, & routing) with a [React frontend](https://github.com/facebookincubator/create-react-app). |
4 | 4 |
|
| 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 | + |
5 | 12 | To deploy a frontend-only React app, use the static-site optimized |
6 | 13 | ▶️ [create-react-app-buildpack](https://github.com/mars/create-react-app-buildpack) |
7 | 14 |
|
8 | | -⤵️ [Switching from create-react-app-buildpack](#switching-from-create-react-app-buildpack)? |
9 | | - |
10 | 15 |
|
11 | 16 | ## Design Points |
12 | 17 |
|
@@ -78,7 +83,33 @@ If an app was previously deployed with [create-react-app-buildpack](https://gith |
78 | 83 | git commit -m 'Migrate from create-react-app-buildpack to Node server' |
79 | 84 | git push heroku master |
80 | 85 | ``` |
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 | + ``` |
82 | 113 |
|
83 | 114 | ## Local Development |
84 | 115 |
|
|
0 commit comments