So, I am following this tutorial on setting up a front-end/back-end with create-react-app boilerplate:
https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/
The APIs I have set up to be sent to the backend don't work in production mode.
I use this in client/package.json to proxy to the backend:
"proxy": "http://localhost:8081/",
And I serve up the files like this in production on my node backend:
app.set('port', (process.env.PORT || 8081));
// Express only serves static assets in production
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
// Always return the main index.html on routes that should return a "page" (e.g. /contact),
// so react-router will render the route in the client
app.get('*/:page', (req, res) => {
res.sendFile(path.resolve('client/build', 'index.html'));
});
};
But the API calls aren't called properly in production mode. Any idea why?
And secondarily: Will I need to anything special to make it run on an nginx server?
via Tulun
No comments:
Post a Comment