Viewing NodeJS projects on other devices in the network

一曲冷凌霜 提交于 2020-12-06 05:16:56

问题


I’m trying to view a CreateReactApp project from a different device. I tried setting the host to 0.0.0.0 by setting the “start” script to:

"start": "cross-env HOST=0.0.0.0 react-scripts start".

Though the console did log

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].

I could not access this project from another device on the same network using the computer’s IP.

At the same time I managed to access other projects (from a “tomcat” local server) on the same computer from the same device using the computer's IP. Any idea why this might be happening? My environment: Windows10. I tried it on both ‘PowerShell’, and ‘Bash on Ubuntu on Windows (WSL)’, on more than one Create-React-App project.


回答1:


By default, Create React App serves the app in localhost:3000. So accessing <ip address of machine serving the app>:3000 should work for devices in the same network.

Revert the change in start script in package.json and open the app in <ip adress>:3000




回答2:


Windows Defender Firewall was blocking the connection. It had a blocking rule for "NodeJs: Server Side JavaScript". To open the connection:

Settings => Update and Security => Windows Security => Firewall and network protection => Advanced Settings => Inbound rules => remove rules blocking node server.

Windows did not show a notification when blocking. It might be that at some point for some reason I authored it to block a connection to the nodeJS server.



来源:https://stackoverflow.com/questions/50703523/viewing-nodejs-projects-on-other-devices-in-the-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!