node 跨域请求设置

http.createServer((req,res)=>{
//设置允许跨域的域名,代表允许任意域名跨域
res.setHeader(“Access-Control-Allow-Origin”,"
");
//跨域允许的header类型
res.setHeader(“Access-Control-Allow-Headers”,“Content-type,Content-Length,Authorization,Accept,X-Requested-Width”);
//跨域允许的请求方式
res.setHeader(“Access-Control-Allow-Methods”,“PUT,POST,GET,DELETE,OPTIONS”);
//设置响应头信息
res.setHeader(“X-Powered-By”,’ 3.2.1’)
//让options请求快速返回
if(req.method == “OPTIONS”){return res.end();}
}
}).listen(3000);

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页