【发布时间】:2015-05-28 20:12:47
【问题描述】:
跨域请求未设置cookie。我的服务器在 localhost:8000 中运行,客户端在 localhost:9000 中运行。服务器 nodejs/express 上的 cors 设置是
app.use(function(req, res, next) {
console.log(req.method);
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Cache-Control, Authorisation");
if (req.method === 'OPTIONS') {
return res.send(200);
} else {
return next();
}});
客户端使用Angularjs,cors配置为
SelappsAdmin.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}])
【问题讨论】:
标签: angularjs node.js cookies cross-domain