报错图片
答案:
app.all('*', function(req, res, next) {res.header('Access-Control-Allow-Origin', ':3000');res.header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');res.header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Origin, Accept');res.header('Access-Control-Allow-Credentials', 'true');if (req.method.toLowerCase() === 'options') {res.send(200);} else {next();}});
原因 :
如图显示,会优先请求OPTIONS
方法,假如这时候没有返回200
这时候不会发出PSOT
请求
所以这时候后端更改为在处理登录 url 时不需要对OPTIONS
方法进行身份验证。
相关链接
1.stack overflow
2. GitHub