无法通过公共 IP 地址访问 create-react-app

时间:2021-03-24 18:01:59

标签: node.js reactjs npm ip

我试图通过访问 [IP_ADDRESS]:3001 从另一台计算机打开我的 create-react-app,但我的 react 应用程序只能在 localhost:3001 上连接。我已尝试执行以下命令但出现错误:

C:\Users\HP\OneDrive\mealplanner\client>HOST=0.0.0.0 npm run start
'HOST' is not recognized as an internal or external command, operable program or batch file.

所以我将变量添加到我的 npm 启动脚本中:

"scripts": {
    "start": "set PORT=3001 && set HOST=0.0.0.0 && react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}

这不会给我一个错误,但是,我在命令提示符下收到此警告:

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: https://cra.link/advanced-config

然后,在访问 localhost:3001[IP_ADDRESS]:3001 时,我从 chrome 收到此错误:

This site can’t be reached

0 个答案:

没有答案
相关问题