0

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. 
alyx
  • 2,593
  • 6
  • 39
  • 64
  • Do you already have `$httpProvider.defaults.useXDomain = true;` in your Angular config? – Owen Sep 25 '14 at 16:42
  • 1
    Are you doing this locally directly to your own server? Your error says you are trying to send a request to `www.meetup.com`. They probably do not respond with CORS headers, however their API does. – mscdex Sep 25 '14 at 16:44
  • I'm trying to authenticate users via Meetup social login using Passport in Node. I had to modify the way routes work normally for /auth/meetup in Passport so I'm trying to GET request passport (on port 2997) from the web interface (port 80) – alyx Sep 25 '14 at 17:05

1 Answers1

1

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

Community
  • 1
  • 1
Reena
  • 1,109
  • 8
  • 16