0
我使用的角度來調用GET請求快遞/節點:節點/ Express的訪問控制允許來源「CORS不工作
$http.get('/auth/'+type).
success(function(user){
}).
error(function(err){
if (err){
$scope.alerts.addAlert('danger',err);
}
});
的快遞/節點配置它(我認爲包括CORS正確):
var express = require('express'),
app = module.exports.app = express();
//express compression
var oneDay = 86400000;
var compression = require('compression');
app.use(compression());
// CORS support.
app.all('*', function(req, res, next){
if (!req.get('Origin')) return next();
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET');
res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
if ('OPTIONS' == req.method) return res.send(200);
next();
});
app.use(express.static(__dirname + '/app/dist', { maxAge: oneDay }));
當我火$ http.get,我得到一個訪問控制錯誤:
XMLHttpRequest cannot load http://www.meetup.com/authenticate/?oauth_token=f515918e2415f9a321ljsf34. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:2997' is therefore not allowed access.
你已經有'$ httpProvider.defaults.useXDomain = TRUE;'你的角度配置? – Owen 2014-09-25 16:42:09
你是否直接在本地進行自己的服務器?您的錯誤表明您正嘗試向「www.meetup.com」發送請求。他們可能不會用CORS頭文件進行響應,但是他們的API可以。 – mscdex 2014-09-25 16:44:01
我試圖通過在節點中使用Passport進行Meetup社交登錄來驗證用戶身份。我不得不在Passport中修改/ auth/meetup路徑的正常工作方式,所以我試圖從Web界面(端口80)獲取請求通行證(在端口2997上) – alyx 2014-09-25 17:05:51