1

Trying to port an app over which is based on a bunch of node modules using http.

Is there a solution to this, other than rewriting libraries for fetch?

RadiantHex
  • 24,907
  • 47
  • 148
  • 244
  • What is `http`? – Chase DeAnda Jun 05 '17 at 21:09
  • @ChaseDeAnda standard Node library for http requests – RadiantHex Jun 05 '17 at 21:14
  • 1
    If you knew exactly which features of the http module were being used, then you could explore making an http polyfill that uses fetch under the hood to see if you're using something that fetch can't do or if some combination of fetch and/or XMLHttpRequest could serve as the underlying engine for everything you're doing with an http module wrapper on top of it. – jfriend00 Jun 05 '17 at 21:43
  • BTW if you are starting whatever project from scratch instead of using http you may use [axios](https://github.com/axios/axios) it uses http if is in node, fetch if is in react-native and xmlHttpRequest if is in web. – Chris Gomez Jul 23 '18 at 13:07

1 Answers1

-1

http is only an issue on iOS 9+. You can just allow the http like this - React Native fetch() Network Request Failed

Here is where it is mentioned in the docs - http://facebook.github.io/react-native/releases/0.44/docs/running-on-device.html#app-transport-security

Go to your info.plist file here: /Users/Noitidart/Documents/YOUR_PROJECT_NAME/ios/YOUR_PROJ_NAME/Info.plist

then find NSExceptionDomains. You will see localhost is already there. You can add other domains here. This is what it looks like to allow bing as http:

<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>bing.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

You can allow all http by setting:

<key>NSAllowsArbitraryLoads</key>
<true/>

Per - https://stackoverflow.com/a/38427829/1828637

On Android, http is not a problem.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    I don't really think he is asking what you think he is asking, he is asking about the http module that it's in the core nodejs packages, but it can't be used in react native as it doesn't have that module. – Chris Gomez Jul 23 '18 at 12:03