reactjs - 在网络中的其他设备上查看 NodeJS 项目
问题描述
我正在尝试从其他设备查看 CreateReactApp 项目。我尝试0.0.0.0
通过将“start”脚本设置为:
"start": "cross-env HOST=0.0.0.0 react-scripts start".
虽然控制台确实记录了
Attempting to bind to HOST environment variable: 0.0.0.0
If this was unintentional, check that you haven't mistakenly set it in your
shell.
Learn more here: [URL BLOCKED BY GITHUB].
我无法使用计算机的 IP 从同一网络上的另一台设备访问此项目。
同时,我设法使用计算机的 IP 从同一设备访问同一计算机上的其他项目(从“tomcat”本地服务器)。知道为什么会发生这种情况吗?我的环境:Windows10。我在不止一个 Create-React-App 项目中尝试了“PowerShell”和“Windows 上的 Ubuntu (WSL) 上的 Bash”。
解决方案
默认情况下,Create React App 在localhost:3000
. 因此访问<ip address of machine serving the app>:3000
应该适用于同一网络中的设备。
还原 package.json 中启动脚本的更改并在其中打开应用程序<ip adress>:3000
推荐阅读
- javascript - 单击时隐藏/显示部分表单。如何调试?
- ruby-on-rails - 如何通过从其他表中查找 id 来应用范围
- python - 以编程方式设置python路径
- javascript - 通过 Js 检索共享点列表
- javascript - 在这种情况下,你能在循环中返回一个布尔值吗
- haskell - 2019 年 Yesod 正则表达式
- python - 类之间的 NaN
- simulation - 如何在 Netlogo 中随时间改变海龟的颜色?
- javascript - 是否有任何内置函数,例如在 javascript 中查找所有内容?
- javascript - 这个循环是同步执行的吗?