且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

角/节点/ EX preSS /护照 - 连接至Facebook时出现问题(CORS)

更新时间:2022-05-31 07:51:50

我用角与节点/ EX preSS为好,下面的函数适用于我用我自己的后端服务(我目前不使用它与Facebook是诚实的),所以只检查出来:

I'm using Angular with Node/Express as well, and the following function works for me with my own backend services (I'm currently not using it with Facebook to be honest), so just check it out:

var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, Access-Control-Allow-Origin');
    res.header("Access-Control-Max-Age", "86400"); // 24 hours

    // intercept OPTIONS method
    if ('OPTIONS' == req.method) {
        res.send(200);
    }
    else {
        next();
    }
};

然后,你需要使用它锡 app.confiure()方法如下:

// configure Express
app.configure(function() {
   app.use(allowCrossDomain);
    ...
});

要使用它之前所有其他directrives这一点很重要!

It's important to use it BEFORE all other directrives!