express跨域
原创
©著作权归作者所有:来自51CTO博客作者不秃头的小李同学的原创作品,请联系作者获取转载授权,否则将追究法律责任
Access to fetch at 'http://localhost:3000/fetch/fetchGet/456' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
解决方法:
服务端添加允许跨域(以下为node.js express框架)
// 允许跨域
app.all('*', function(req, res, next) {
res.setHeader(
'Access-Control-Allow-Origin', '*'
)
next();
})