Node.js 使用axios的HTTPrequest会导致CORS错误
我构建了自己的API,它运行在端口5000上。每当我想向它发出请求时,都会出现以下错误:Node.js 使用axios的HTTPrequest会导致CORS错误,node.js,cors,axios,Node.js,Cors,Axios,我构建了自己的API,它运行在端口5000上。每当我想向它发出请求时,都会出现以下错误: Access to XMLHttpRequest at 'http://localhost:5000/user' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Con
Access to XMLHttpRequest at 'http://localhost:5000/user' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我已经做了一些研究,但唯一有效的是chrome扩展,这并不理想
Here's what i did :
const config = {
headers : {
'Content-Type' : 'application/json',
'Access-Control-Allow-Origin': '*'
}
};
简单地说,若服务器不允许CORS,浏览器就会阻止响应。因此,如果您在API中使用NodeJS,请使用这个