项目中访问本地node服务跨域问题

# 访问本地node服务跨域问题     
1 //CORS跨域接口
2     res.header('Access-Control-Allow-Origin', 'http://localhost:3000'); // * 这个表示任意域名都可以访问,这样写不能携带cookie了 || 'http://localhost:5080'
3     res.header('Access-Control-Allow-Credentials', true); // 允许服务器端发送Cookie数据,
4                                                           // 若前端上axios.defaults.withCredentials = true设置为true了,
5                                                           // 则Access-Control-Allow-Credentials必须为true,否则会请求失败,报错
6     res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');//它也是一个逗号分隔的字符串,表明服务器支持的所有头信息字段
7     res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');  //设置方法
原文地址:https://www.cnblogs.com/slightFly/p/15270976.html