简体   繁体   English

如何通过 usb 配置在移动设备上运行的 React 电容器应用程序,使 http 请求 sendbird 作为本地主机而不是其 IP 地址?

[英]How to configure a react capacitor app running on mobile by usb to make http request to sendbird as localhost instead of its IP address?

I have a React webapp that I have converted it to native app using Capacitor.我有一个 React webapp,我已经使用 Capacitor 将它转换为本机应用程序。 For live reloading, I had to edit capacitor.config.json as follows:对于实时重新加载,我必须按如下方式编辑 capacitor.config.json:

const config: CapacitorConfig = {
  //
  webDir: 'build',
  bundledWebRuntime: false,
  server: {
    url: 'http://192.XXX.XXX:3000',
    cleartext: true
  },
};

This works just fine until the app makes a request to sendbird for initialization.在应用程序向 sendbird 发出初始化请求之前,这一切正常。 I get the error message: 'SendBirdCall needs https connection, except for 'localhost' or '127.0.0.1'.我收到错误消息:'SendBirdCall 需要 https 连接,'localhost' 或 '127.0.0.1' 除外。 I tried to setup an express https server but failed.我试图设置一个 express https 服务器但失败了。 Later I created two channels using ngrok - one for the server and one for the app.后来我使用 ngrok 创建了两个通道——一个用于服务器,一个用于应用程序。 The sendbird request was successful but the graphql websocket was failing as ngrok does not support websocket links, also tried a tcp link but it failed as well. sendbird 请求成功,但 graphql websocket 失败,因为 ngrok 不支持 websocket 链接,还尝试了 tcp 链接,但也失败了。

I have another app that I created using the Sendbird React Native Quickstart project and I did not need to do any configuration for that.我有另一个使用 Sendbird React Native Quickstart 项目创建的应用程序,我不需要为此进行任何配置。 What could be done in order to make sendbird request using localhost from mobile connected via usb while also being able to have a ws connection?为了使用本地主机从通过 usb 连接的移动设备发出 sendbird 请求,同时还能够建立 ws 连接,可以做些什么?

Try to change the url :尝试更改url

const config: CapacitorConfig = {
  ...
  server: {
    url: 'http://localhost:3000',
    cleartext: true
  },
};

And after connecting a physical device execute the following:连接物理设备后执行以下操作:

cd $ANDROID_HOME/platform-tools
./adb reverse tcp:3000 tcp:3000

Where $ANDROID_HOME is the Android SDK directory.其中$ANDROID_HOME是 Android SDK 目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用在本地主机上运行的 API 从反应应用发出 http 请求 - Making an http request from react app with API running on localhost 在手机上运行 localhost react app - Running localhost react app on mobile phones 禁止 (403) 在“构建 React 应用程序”中发布请求,但在“http://localhost:3000/”和 PostMan 上运行的 React App 可以正常工作 - Forbidden (403) Post Request in a "Build React App" but work fine with React App running on "http://localhost:3000/" and PostMan 如何将 React App localhost:3000 IP 更改为我的 IP? - How to change the React App localhost:3000 IP to my IP? 在React中将所有内容放在http:// localhost:3000 / app而不是http:// localhost:3000 /的最简单方法 - Simplest way to put everything under http://localhost:3000/app instead of http://localhost:3000/ in React 如何在反应应用程序中在移动设备上“隐藏地址栏”? - How to "hide the address bar" on mobile in a react app? 对 localhost 使用错误的 IP 地址做出反应 - React using wrong IP address for localhost 如何让 creat-react-app build 监听 0.0.0.0 而不是 localhost? - How to make creat-react-app build listen on 0.0.0.0 instead of localhost? 如何在 Spring Boot 后端配置 React 应用程序以在 localhost 8080 中启动 - How configure react app to start in localhost 8080 in spring boot backend 为什么我可以使用 IP 地址从 React 应用程序调用 api 端口,但当我使用“localhost”时却不能 - Why can I call api port from React app using ip address, but not when I use "localhost"
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM