代码之家  ›  专栏  ›  技术社区  ›  Ben Carp

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

  •  2
  • Ben Carp  · 技术社区  · 8 年前

    我正在尝试从其他设备查看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。我在powershell和ubuntu on windows(wsl)上的bash上,在多个create react应用程序项目上都试过。

    2 回复  |  直到 8 年前
        1
  •  2
  •   sudo bangbang    8 年前

    默认情况下,create react app在 localhost:3000 . 所以访问 <ip address of machine serving the app>:3000 应该适用于同一网络中的设备。

    还原package.json中开始脚本的更改并在中打开应用程序 <ip adress>:3000

        2
  •  1
  •   Ben Carp    8 年前

    Windows Defender防火墙正在阻止连接。它有一个“nodejs:server-side javascript”的阻塞规则。打开连接:

    settings=>update and security=>windows security=>firewall and network protection=>advanced settings=>inbound rules=>删除阻止节点服务器的规则。

    Windows在阻止时未显示通知。可能出于某种原因,我编写它是为了阻止与nodejs服务器的连接。