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.
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.
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.)
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.
The proxy feature isn't meant for production.
This might help further explain: https://github.com/facebookincubator/create-react-app/issues/1087#issuecomment-262611096
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With