CORS配置后为什么还是报跨域错误?
我在本地开发时用的是 http://localhost:3000,后端接口在 http://localhost:8080。明明已经在后端加了 CORS 配置允许 origin,但浏览器还是报跨域错误,说“请求的资源中没有 ‘Access-Control-Allow-Origin’ 头”。是不是我哪里配错了?
我用的是 Express,配置代码是这样的:
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
暂无解答