允许跨域在node.js中不起作用

时间:2013-05-23 07:12:34

标签: node.js cross-domain

我正在运行apache上的骨干客户端和node.js上的服务器。当我运行node.js时,它总是给出:
    else {auth:false;}

当我从骨干网中保存时,它会在控制台上出错:

 XMLHttpRequest cannot load
 http://localhost:3000/formSave. 
 Origin http://localhost is not allowed by Access-Control-Allow-Origin.


var allowCrossDomain = function(req, res, next) {
var allowedHost = [
    'http://localhost',
    'http://backbonetutorials.com'
];

if(allowedHost.indexOf(req.headers.origin) !== -1) {
    res.header('Access-Control-Allow-Credentials', "*");
    res.header('Access-Control-Allow-Origin', req.headers.origin);
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept,     Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version');
    next();
} else {
    res.send({auth: false});
}
};    
 app.configure(function(){
 app.use(allowCrossDomain);
 });

此代码有什么问题

0 个答案:

没有答案