Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 5fbc974

Browse files
authored
📚 document proxy for local development to match deployment
1 parent c05a456 commit 5fbc974

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ Prevent downgrade attacks with [HTTP strict transport security](https://develope
233233

234234
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.
235235

236-
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`:
236+
#### Proxy for deployment
237+
238+
The [`heroku/static` buildpack](https://github.com/heroku/heroku-buildpack-static) (see: 🏙 [Architecture](#user-content-architecture-)) provides [Proxy Backends configuration](https://github.com/heroku/heroku-buildpack-static/blob/master/README.md#proxy-backends) to utilize Nginx for high-performance proxies in production.
239+
240+
Add `"proxies"` to `static.json`:
237241

238242
```json
239243
{
@@ -252,6 +256,27 @@ Then, point the React UI app to a specific backend API:
252256
heroku config:set API_URL="https://api.example.com"
253257
```
254258

259+
#### Proxy for local development
260+
261+
create-react-app itself provides a built-in [proxy for development](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#user-content-proxying-api-requests-in-development). This may be configured to match the behavior of [proxy for deployment](#user-content-proxy-for-deployment).
262+
263+
Add `"proxy"` to `package.json`:
264+
265+
```json
266+
{
267+
"proxy": {
268+
"/api": {
269+
"target": "http://localhost:8000",
270+
"pathRewrite": {
271+
"^/api": "/"
272+
}
273+
}
274+
}
275+
}
276+
```
277+
278+
Replace `http://localhost:8000` with the URL to your local or remote backend service.
279+
255280

256281
### Environment variables
257282

0 commit comments

Comments
 (0)