【发布时间】:2018-05-08 21:00:19
【问题描述】:
我正在尝试在 express 应用上设置 CORS 标头,但我不知道为什么它不起作用:
app.use(function(req, res, next){
res.append('Access-Control-Allow-Origin','*');
res.set("Access-Control-Allow-Methods","GET, POST, OPTIONS");
res.set("Access-Control-Allow-Headers","Content-Type, Authorization, Content-Length, X-Requested-With");
if ("OPTIONS" == req.method){
res.send(200);
}
console.log("Set CORS Header");
next();
});
我也尝试过使用 res.header、res.setheader 和 res.append,但都没有正确设置标头,但是每次通过请求时控制台上都会出现“设置 CORS 标头”消息。
编辑:看起来它可能与 AWS EC2 有关?
完整的服务器代码在这里:https://github.com/rossgriebenow/wkdu-music-webapp/blob/master/WKDU_SQL.js
【问题讨论】:
-
res.append和res.set有什么区别?
标签: node.js amazon-web-services express amazon-ec2 cors