Failed to load http://localhost:3000/products: The 'Access-Control-Allow-Origin' header has a value

用node写了个接口,但是启动前端的时候一直请求不到数据,报错

Failed to load http://localhost:3000/products: The ‘Access-Control-Allow-Origin’ header has a value ‘http://127.0.0.1:3000’ that is not equal to the supplied origin.

后来在node后端设置了一个请求头,也就是serve,on()里加了一行代码,设置一个请求头,问题就解决了。
不是刚开始想的跨域问题

res.setHeader("Access-Control-Allow-Origin", "*");
发布了177 篇原创文章 · 获赞 31 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43560272/article/details/104281650