[英]How to change the React App localhost:3000 IP to my IP?
我正在使用付费 API。他们将我的 ip 列入白名单。我可以从 Thunder Client 和 postman 应用程序获取数据。 但是当我要从我的反应应用程序中获取数据时。 什么都做不了。 基本上 localhost:3000 托管在不同的 IP 上,对吗? 那么如何从我的 IP(103.124.251.85) 托管我的 react-app 本地主机
要更改 React 应用程序的主机,您只需在您的环境中添加主机,如下所示:
HOST=you_system_ip
或者您也可以在 package json 文件中添加脚本,如下所示:
"start": "HOST=you_system_ip react-scripts start",
在您的 package.json 中,您可以将“启动”脚本更改为
"start": "SET HOST=103.124.251.85 && react-scripts start"
或者,您可以在项目的根目录中创建一个 file.env 并设置:
HOST=103.124.251.85
如果您需要在 HTTPS 上运行您的应用程序,请执行以下操作:
"scripts": {
"prestart": "type dev_certs\\cert.key dev_certs\\cert.crt > dev_certs\\server.pem && copy /y dev_certs\\server.pem node_modules\\webpack-dev-server\\ssl",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
PORT=443
HOST=103.124.251.85
HTTPS=true
如果您遇到错误“allowedHosts”为空:
options.allowedHosts[0] should be a non-empty string.
您可以通过传递以下环境变量来禁用此检查:
DANGEROUSLY_DISABLE_HOST_CHECK=true HOST=xxxx npm run start
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.