You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+80-4Lines changed: 80 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -147,21 +147,96 @@ Prevent downgrade attacks with [HTTP strict transport security](https://develope
147
147
148
148
### Environment variables
149
149
150
-
[`REACT_APP_*`](https://github.com/facebookincubator/create-react-app/blob/v0.2.3/template/README.md#adding-custom-environment-variables)and [`NODE_*`](https://github.com/facebookincubator/create-react-app/pull/476)environment variables are supported on Heroku during the compile phase, when `npm run build` is executed to generate the JavaScript bundle.
150
+
[`REACT_APP_*`](https://github.com/facebookincubator/create-react-app/blob/v0.2.3/template/README.md#adding-custom-environment-variables) environment variable are supported with this buildpack.
151
151
152
-
Set [config vars on a Heroku app](https://devcenter.heroku.com/articles/config-vars) like this:
152
+
🤐 *Be careful not to export secrets. These values may be accessed by anyone who can see the React app.*
153
+
154
+
Set [env vars on a Heroku app](https://devcenter.heroku.com/articles/config-vars) like this:
153
155
154
156
```bash
155
157
heroku config:set REACT_APP_HELLO='I love sushi!'
156
158
```
157
159
158
-
♻️ The app must be re-deployed for this change to take effect, because the automatic restart after a config var change does not rebuild the JavaScript bundle.
160
+
For local development, use [dotenv](https://www.npmjs.com/package/dotenv) to load variables from a `.env` file. *Requires at least create-react-app 0.7.*
161
+
162
+
#### Compile-time vs Runtime
163
+
164
+
Two versions of variables are supported. In addition to compile-time variables applied during [build](https://github.com/facebookincubator/create-react-app#npm-run-build), this buildpack supports runtime configuration as well.
<code>Runtime env var example: { env.REACT_APP_HELLO }</code>
212
+
);
213
+
}
214
+
}
215
+
```
216
+
217
+
⚠️ *Avoid setting backslash escape sequences, such as `\n`, into Runtime config vars. Use literal UTF-8 values only; they will be automatically escaped.*
218
+
219
+
#### Add-on config vars
220
+
221
+
🤐 *Be careful not to export secrets. These values may be accessed by anyone who can see the React app.*
222
+
223
+
Use a custom [`.profile.d` script](https://devcenter.heroku.com/articles/buildpack-api#profile-d-scripts) to make variables visible to the React app by prefixing them with `REACT_APP_`.
224
+
225
+
1. create `.profile.d/000-react-app-exports.sh`
226
+
1. make it executable `chmod +x .profile.d/000-react-app-exports.sh`
227
+
1. add an `export` line for each variable:
228
+
229
+
```bash
230
+
export REACT_APP_ADDON_CONFIG=${ADDON_CONFIG:-}
231
+
```
232
+
1. set-up & use [Runtime configuration](#runtime-configuration) to access the variables
233
+
234
+
For example, to use the API key for the [Filestack](https://elements.heroku.com/addons/filepicker) JS image uploader:
0 commit comments