node 跨域請求設置
阿新 • • 發佈:2019-03-17
options 響應頭信息 new all code 允許 tro ont 頭信息
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);
node 跨域請求設置