fullstackreact / food-lookup-demo

A demonstration of using `create-react-app` with a server
MIT License
1.19k stars 373 forks source link

Proxy don't work after production build #40

Closed AdamDomagalsky closed 6 years ago

AdamDomagalsky commented 7 years ago

I've cloned the repo, everything is working fine, but after runing npm run build and running a prod version of clinet - it looks like we are loosing connection between client and API.

Any ideas how to fix that?

lomoY commented 7 years ago

does it work well in your development environment? I follow the suggestion in this repo but it not works for me.

Then I set the below code in my server.js:

app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
  });
auser commented 6 years ago

Yes, if you run the production build using the following code, the server will serve the production version of the application:

NODE_ENV=production npm run start

This will work only after you build the client:

(cd client && npm run build)