如何从连接到同一网络的另一台计算机打开 create-react-app? [英] How to open a create-react-app from another computer connected to the same network?
问题描述
我正在使用 create-react-app 并在其默认端口 localhost:3000 中托管,并想从另一台设备上访问它同一个网络.
I am using create-react-app and hosting in its default port localhost:3000 and want to access this from another device on the same network.
我获得了主机 IP 的 IP(使用 ifconfig)192.168.0.5 并尝试打开 192.168.0.5:3000 但这没有用.
I got the IP of my host's IP (using ifconfig) 192.168.0.5 and tried opening 192.168.0.5:3000 but that did not work.
有什么办法可以实现吗?
Is there any way to achieve this?
推荐答案
只需运行 HOST=0.0.0.0 npm run start
.
然后从网络上的另一台设备打开 url.
Simply run HOST=0.0.0.0 npm run start
.
Afterwards open the url from another device on the network.
在您的情况下,192.168.0.5:3000
会起作用.
In your case, 192.168.0.5:3000
would work.
文档设置 HOST 环境变量.
Documentation for setting HOST environment variables.
这篇关于如何从连接到同一网络的另一台计算机打开 create-react-app?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!