node express 跨域设置

在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();
});

你可能感兴趣的:(node express 跨域设置)