API NodeJS Express和Firebase for React native

时间:2018-01-09 08:42:28

标签: node.js firebase express react-native

我开发了一个API(节点js,express和firebase)来在我的原生应用中使用它来反应我的API的结构: API:允许您选择一些尊重特定条件的用户,并在调用允许修改数据库firebase中字段的函数后:当我在浏览器上测试时,API工作得非常好。

以下是我的API的结构:

    router.get ('/: senderID /: numberOfShare /: drop', function (req, res, next) { 
      // Code that allows users to be selected from the database FOREACH {
         // call to a function (function2) which allows to modify the data of users in the BDD
   }
    // define the function2 here { modify user data in the database
   } 
  }

我的问题是:如何从我的本机应用程序中正确利用我的API?

我做了一个测试,但没有工作。

测试:

shareDrop (drop, parent) {
   fetch ('192.168.1.4:3000/users/senderID/numberOfShare/drop',
    { method: 'GET', 
    headers: { 
      Accept: 'application / json', 
      'Content-Type': 'application / json', 
    } 
    params: JSON.stringify
     ({ 
       senderID: this.state.uid,
        numberOfShare: 'parent.state.numberOfShare',
        drop: drop 
      }), 
    }); 
}

1 个答案:

答案 0 :(得分:0)

确保您的info.plist允许localhost或其他API与之通信。

的Info.plist

   <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>localhost</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
      </dict>
    </dict>

Here是我构建的一个回购,用于演示react-native应用如何与node服务器和mongo数据库进行通信。也许你可以在那里找到一些灵感。