【问题标题】:API NodeJS Express and Firebase for React native用于 React 本机的 API NodeJS Express 和 Firebase
【发布时间】:2018-01-11 11:34:52
【问题描述】:

我开发了一个 API(node 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
   } 
  }

我的问题是:如何从我的 react-native 应用程序中正确利用我的 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 
      }), 
    }); 
}

【问题讨论】:

    标签: node.js firebase express react-native


    【解决方案1】:

    确保您的 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 是我构建的一个 repo,它演示了 react-native 应用程序如何与 node 服务器和 mongo 数据库通信。也许你可以在那里找到一些灵感。

    【讨论】:

    • 好的,谢谢您的评论
    猜你喜欢
    • 2020-03-21
    • 2020-11-22
    • 1970-01-01
    • 2022-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2021-06-15
    相关资源
    最近更新 更多