// 设置允许跨域访问 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",1) next(); });