查看网络中其他设备上的 NodeJS 项目

Viewing NodeJS projects on other devices in the network

我正在尝试从不同的设备查看 CreateReactApp 项目。我尝试通过将“开始”脚本设置为

来将主机设置为 0.0.0.0
"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。我在“PowerShell”和“Bash on Ubuntu on Windows (WSL)”以及多个 Create-React-App 项目上都进行了尝试。

默认情况下,Create React App 为 localhost:3000 中的应用提供服务。因此访问 <ip address of machine serving the app>:3000 应该适用于同一网络中的设备。

还原 package.json 中启动脚本的更改并在 <ip adress>:3000

中打开应用程序

Windows Defender 防火墙阻止了连接。它有一个针对 "NodeJs: Server Side JavaScript" 的阻止规则。要打开连接:

设置 => 更新和安全 => Windows 安全 => 防火墙和网络保护 => 高级设置 => 入站规则 => 删除阻止节点服务器的规则。

Windows 阻止时没有显示通知。可能是出于某种原因,我在某个时候编写了它来阻止与 nodeJS 服务器的连接。