Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm run build does not use proxy

I have a working react.js application, which works using npm start (app built using create-react-app). When I try to run npm run build, it builds the application. I serve it using

serve -s build -l 3000

It loads the first dashboard page but does not communicate with the server. I have put console.log statements in server to check for any requests coming in, but it never logs anything... which means the client does not talk to the server. I have proxy statement in package.json to connect to server on port 3300. This works in development mode but in production mode it seems to not pickup the proxy settings in the package.json.

Please guide... this is my first time switching to production mode... any guidance on switching to production mode would help.

BTW I use react-loadable as well...

like image 427
Avinash Avatar asked Oct 23 '25 15:10

Avinash


2 Answers

The proxy field in package.json is only used in development by webpack-dev-server. You can learn more about this here

like image 109
Prithwee Das Avatar answered Oct 25 '25 07:10

Prithwee Das


Thanks for all the help guys....

Finally, I understood that "npm run build" just creates the static files to deploy. But how to use it, is our hands. :)

I copied the build folder inside the /server folder and added the following line in my root server.js file itself. Basically, served the static files from /server/build folder and it all works beautifully.

app.use('/', express.static(__dirname+'/server/build'))

Thanks for the support. :)

like image 30
Avinash Avatar answered Oct 25 '25 07:10

Avinash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!