No idea why I can't google this, but I can't seem to figure out how to proxy my api calls in the webpack.config.prod.js file of my create-react-app. Putting it in the package.json file won't do because I need a different proxy locally.
I have it set up in the webpackDevServer.config.js, works great by putting it in the module.exports
object. But it fails to build when I do the same in the webpack.config.prod.js. How to set this up for prod?
proxy: {
'/myService/*': 'https://myServiceEndPoint/',
},
No idea why I can't google this, but I can't seem to figure out how to proxy my api calls in the webpack.config.prod.js file of my create-react-app. Putting it in the package.json file won't do because I need a different proxy locally.
I have it set up in the webpackDevServer.config.js, works great by putting it in the module.exports
object. But it fails to build when I do the same in the webpack.config.prod.js. How to set this up for prod?
proxy: {
'/myService/*': 'https://myServiceEndPoint/',
},
Share
Improve this question
asked Sep 19, 2018 at 19:09
jmargolisvtjmargolisvt
6,0985 gold badges31 silver badges49 bronze badges
1 Answer
Reset to default 5Proxy is not meant to be used in production environment.
https://github./facebook/create-react-app/issues/1087#issuement-262611096
In production, CRA produces a static bundle. At this point you can do anything you want with it. The notion of a proxy doesn't make sense there because there is no development server. It is up to you to serve the bundle with any server, and you indeed can tweak the API call URLs depending on process.env.NODE_ENV or a custom environment variable