[英]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.