express設置允許跨域請求
//設置跨域訪問 app.all("*", function (req, res, next) { //設置允許跨域的域名,*代表允許任意域名跨域 res.header("Access-Control-Allow-Origin", req.headers.origin || '*'); // //允許的header類型 res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With"); // //跨域允許的請求方式 res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); // 可以帶cookies res.header("Access-Control-Allow-Credentials", true); if (req.method == 'OPTIONS') { res.sendStatus(200); } else { next(); } })