Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create-React-App Proxy in Production Build

I'm using create-react-app with an express backend. I have the backend running on port 3001, and the frontend runs through port 3000 when in dev mode. I have "proxy": "http://localhost:3001" in my package.json and the api works perfectly.

When I use yarn build, however, and then run serve -s build, the api calls are simply not being made. I'm not sure why it doesn't work in production, when it does in dev.

Any help would be much appreciated.

like image 347
X88B88 Avatar asked Aug 28 '17 02:08

X88B88


People also ask

Does proxy work in production React?

In production we can't use (proxy).. instead we can set a variable in the frontend for the backend URL, and vise versa. Let's start with backend configurations: app.

Can you use create React app for production?

For production apps that will grow, I will not recommend going the create-react-app route. Start with a basic build environment with webpack. Add in your essentials. (babel, css preprocessors, routing, i10n, hot reloading, TDD workflow, lodash/ramda/moment etc.)

How do you proxy A React app?

Proxy Setup with Create-React-App All you have to do is add a proxy field to your package. json file, like shown below. "proxy": "http://localhost:3000", This line instructs the development server to proxy any unknown requests to your API server in development mode.


1 Answers

The proxy feature isn't meant for production.

This might help further explain: https://github.com/facebookincubator/create-react-app/issues/1087#issuecomment-262611096

like image 82
Gavin Gilmour Avatar answered Sep 24 '22 13:09

Gavin Gilmour