我正在 Windows 10 電腦上開發 React Native 應用程式。我安裝了 WSL,在其上設定了我的後端需求,我可以看到我的 api 從 Windows 在本機上回應,這方面沒有問題。
現在我想從我的行動應用程式中調用它 - 既可以從使用 Android Studio 的 Android 模擬器中調用,也可以從透過 wifi 連接到同一本地網路的實體 Android 裝置(使用 Expo)中調用。
使用 Ngrok 它可以工作,將我的本地主機暴露給公共 url,但這不是我想要的。如果可能的話,我希望一切都保留在本地。我的電腦的本地 ipv4 是10.0.0.8
,但該地址上沒有顯示任何內容(不是來自移動應用程序,也不是來自我的桌面瀏覽器,該瀏覽器適用於localhost
)。
我的 Ubuntu 在 WSL 中說:
~$ cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 JB-PC.localdomain JB-PC
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
我的ipconfig
:
Carte Ethernet Ethernet :
Suffixe DNS propre à la connexion. . . : Home
Adresse IPv6 de liaison locale. . . . .: fe80::f04e:ae2b:40b9:3d82%6
Adresse IPv4. . . . . . . . . . . . . .: 10.0.0.8
Masque de sous-réseau. . . . . . . . . : 255.255.255.0
Passerelle par défaut. . . . . . . . . : 10.0.0.138
Carte Ethernet vEthernet (WSL) :
Suffixe DNS propre à la connexion. . . :
Adresse IPv6 de liaison locale. . . . .: fe80::68c3:25c9:588a:a957%17
Adresse IPv4. . . . . . . . . . . . . .: 172.20.32.1
Masque de sous-réseau. . . . . . . . . : 255.255.240.0
Passerelle par défaut. . . . . . . . . :
我應該使用什麼 IP 位址和連接埠來從手機或模擬器存取 API?另外,我還需要在我的 ubuntu 上做些什麼來公開它以便它可用嗎?