Reputation: 2733
I'm using Angular to call a GET request to Express/Node:
$http.get('/auth/'+type).
success(function(user){
}).
error(function(err){
if (err){
$scope.alerts.addAlert('danger',err);
}
});
The Express/Node configuration which ( I think includes CORS correctly):
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 }));
When I fire the $http.get, I get an Access Control error:
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.
Upvotes: 0
Views: 5465
Reputation: 1119
You could check the answer which I have given in this:
How to add 'res.addHeader("Access-Control-Allow-Origin", "*")' in express js?
Hoping it could be helpful
Upvotes: 1