code

Open app.js file in var app = express(); Add this code below

app.all("*", (req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Headers", "*");
  res.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.setHeader("Access-Control-Allow-Credentials", "true")
  next()
});
Copy the code

Pay attention to

Var app = express(); It is even better to add the above snippet after this line