Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit be58f8d

Browse files
authored
📚 Proxy config
1 parent 79be6ea commit be58f8d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Deploy React.js web apps generated with [create-react-app](https://github.com/fa
1515
* [Web server](#web-server)
1616
* [Routing clean URLs](#routing-clean-urls)
1717
* [HTTPS-only](#https-only)
18+
* [Proxy](#proxy)
1819
* [Environment variables](#environment-variables)
1920
* [Set vars on Heroku](#set-vars-on-heroku)
2021
* [Set vars for local dev](#set-vars-for-local-dev)
@@ -174,6 +175,29 @@ Prevent downgrade attacks with [HTTP strict transport security](https://develope
174175

175176
* `max-age` is the number of seconds to enforce HTTPS since the last connection; the example is 90-days
176177

178+
### Proxy
179+
180+
Proxy XHR requests from the React UI in the browser to API backends. Prevent same-origin errors when [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) is not available on the backend.
181+
182+
Configure using [Proxy Backends from the static site buildpack](https://github.com/heroku/heroku-buildpack-static/blob/master/README.md#proxy-backends). Add `"proxies"` to `static.json`:
183+
184+
```json
185+
{
186+
"proxies": {
187+
"/api/": {
188+
"origin": "${API_URL}"
189+
}
190+
}
191+
}
192+
```
193+
194+
Then, point the React UI app to a specific backend API:
195+
196+
```bash
197+
heroku config:set API_URL="https://api.example.com"
198+
```
199+
200+
177201
### Environment variables
178202

179203
[`REACT_APP_*` environment variables](https://github.com/facebookincubator/create-react-app/blob/v0.2.3/template/README.md#adding-custom-environment-variables) are supported with this buildpack.

0 commit comments

Comments
 (0)