Answer the question
In order to leave comments, you need to log in
How to set up a server for React+Express?
There is a backend written in express and running on port 3000. There is a frontend on react + redux on port 8080. When trying to receive data from the backend api, it says that access from different ports is denied. When launched on one port, the backend is triggered by /. Tried to set up cors, but that didn't work either. Can eat, where this problem is described and how to solve it?
Answer the question
In order to leave comments, you need to log in
node :
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
It is better to immediately set up server rendering of the application (you can peep here ) and build the frontend before deploying. In this case, there is no need to start the server with the frontend on a separate port, and for the entire application to work, only express will need to be launched. There are good instructions
for
deploying a node.js application at the office. Passenger website
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question