facebook / react-native

A framework for building native applications using React

Home Page:https://reactnative.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

superagent fails with "Origin is not allowed by Access-Control-Allow-Origin"

jmound opened this issue · comments

I'm unable to perform a simple GET via superagent:

var request = require('superagent');
    request
      .get('http://www.google.com/')
      .end(function(err, res){
        if (res) {
               console.log('yay got ' + err  );
             } else {
               console.log('Oh no! error ' + err );
             }
           });

yields:

2015-04-15 11:53:58.174 [tid:com.facebook.React.JavaScript] "Oh no! error Error: Origin is not allowed by Access-Control-Allow-Origin"

I've performed this making requests to a server running nginx that I control, with a variety of HTTP header permutations, and the note regarding CORS on superagent's docs here, with no success.

I came across this (slightly) related StackOverflow question and answer, and decided to reset the simulator on a whim. It shouldn't have, but it worked.

You may have been developing with the Chrome debugger or UIWebView debugger which enforce CORS, so resetting the simulator state may have reset that :)