【问题标题】:Viewing NodeJS projects on other devices in the network在网络中的其他设备上查看 NodeJS 项目
【发布时间】:2018-06-05 15:15:27
【问题描述】:

我正在尝试从其他设备查看 CreateReactApp 项目。我尝试通过将“start”脚本设置为:

将主机设置为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。我在不止一个 Create-React-App 项目中尝试了“PowerShell”和“Windows 上的 Ubuntu (WSL) 上的 Bash”。

【问题讨论】:

    标签: reactjs npm create-react-app


    【解决方案1】:

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

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

    【讨论】:

    • 我试了很多次都没有成功。也许它在 Windows 上效果不佳。
    【解决方案2】:

    Windows Defender 防火墙阻止了连接。它对“NodeJs:服务器端 JavaScript”有一个阻止规则。打开连接:

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

    Windows 在阻止时未显示通知。可能是出于某种原因,我创作了它来阻止与 nodeJS 服务器的连接。

    【讨论】:

    • 我还发现 Windows (10) 正在通过防火墙阻止 Node。我通过访问Windows Defender Settings => Allow an app through the firewall 解决了这个问题。然后在应用列表中找到Node.js Server-side JavaScript(可能有几个)。确保选中Private 的复选框,然后单击“确定”
    猜你喜欢
    • 2014-12-20
    • 2015-03-13
    • 2015-04-23
    • 1970-01-01
    • 2013-03-05
    • 2014-11-01
    • 2016-09-01
    • 2022-12-18
    • 1970-01-01
    相关资源
    最近更新 更多