express 设置跨域

app.use(function (req, res, next) {
    res.header('Access-Control-Allow-Origin', 'http://localhost:8081');
    //允许的header类型
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.send(200);  //让options尝试请求快速结束
    else
        next();
});
 
 

猜你喜欢

转载自www.cnblogs.com/guangzhou11/p/11575315.html
今日推荐