X88B88
X88B88

Reputation: 651

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.

Upvotes: 46

Views: 43118

Answers (2)

Umar Akmal
Umar Akmal

Reputation: 29

Make rather an ENV file and give the path of your backend like this - REACT_APP_BACKEND_URL=http://localhost:5500 (change port according to your port) and whereever you are calling api - (process.env.REACT_APP_BACKEND_URL/your url) . It will work perfectly in production.

Upvotes: 1

Gavin Gilmour
Gavin Gilmour

Reputation: 6983

The proxy feature isn't meant for production.

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

Upvotes: 29

Related Questions