node express 跨域设置
2017-07-05 本文已影响0人
blank的小粉er
在app.js添加以下代码
//设置请求头
app.all('*', function(req, res, next) {//允许全部跨域
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization,'Origin',Accept,X-Requested-With");
res.header("Access-Control-Allow-Origin", "*");
res.header("Content-Type", "application/json;charset=utf-8");
//console.log('------')
next();
});