Cross-Domain Problem of Front and Rear End Separation

  node.js, question

My front end is REACT+REDUX
Node is used in the back-end and superagent is used to pull back-end data.
Cross-domain problem occurred when pulling local data
XMLHttpRequest cannot loadhttp://localhost:3000/init/redis.No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:3020‘ is therefore not allowed access.

Add the following before the route

//Set server cross-domain permissions
 app.use(function (req, res, next) {
 res.header("Access-Control-Allow-Origin", "*");
 res.header("Access-Control-Allow-Headers", "X-Requested-With");
 res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
 next();
 });