title: CORS: http requests to localhost denied with react-native
body: <p>I have an Express.js server that supports CORS headers running on port 8080, and am trying to make http requests to that port from a React Native app on an iPhone 5, but am getting the following error:</p>
  
  <pre><code>[Error: Request has been terminated
  Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.]
  </code></pre>
  
  <p>The request looks like this:</p>
  
  <pre><code>import request from 'superagent'
  
  const getMarkers = (url, callback) =&gt; {
    request
      .get(url)
      .set('Accept', 'application/json')
      .end(callback)
  }
  
  getMarkers('localhost:8080/markers, this.handleMarkers)
  </code></pre>
  
  <p>And my Express middleware looks like this:</p>
  
  <pre><code>app.use((req, res, next) =&gt; {
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Headers',
      'Origin, X-Requested-With, Content-Type, Accept')
    next()
  })
  </code></pre>
  
  <p>I have allowed 'arbitrary loads' for my project.</p>
  
  <p>These requests run fine when I use the ios Simulator. Also, these requests run fine when I download ngrok, run it in my express server directory, and make the client side requests to the https address provided by ngrok.</p>
  
  <p>My question is: How can I facilitate these requests without using something like ngrok? I'd like to be able to develop quickly using only http and localhost if possible. I'd be very grateful for any insight others can offer on this question!</p>