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();
});
越努力越幸运