我尝试从我的前端使用axios登录,但是出现了这个错误:
XMLHttpRequest cannot load http://localhost:8888/auth/login. Redirect from 'http://localhost:8888/auth/login' to 'http://localhost:8888/auth/login/failure' has been blocked by CORS policy: Request requires preflight, which is disallowed to follow cross-origin redirect.
在后端,我正在使用NodeJS并且已经在每条路由之前放置了这个中间件:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});