如何将React App Localhost更改为IP?3000 IP?
我正在使用付费API。他们将我的IP定为白名。我可以从Thunder Client和Postman应用中获取数据。但是,当我要从React应用程序中获取数据时。没什么做任何事情。基本上是本地主机:3000在不同的IP上托管吗?因此,如何从IP(103.124.251.85)中托管我的React-App本地主机
I am working with a paid API. They whitelisted my ip. I can fetch there data from Thunder Client and postman app. But when I'm going to fetch the data from my react app. It's nothing do anything. Basically localhost:3000 are hosted on different IP right? So how to host my react-app local host from my IP(103.124.251.85)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要更改 React 应用程序的主机,您只需在环境中添加主机,如下所示:
或者您也可以在包 json 文件中添加脚本,如下所示:
To change your host for react app you just have to add HOST in your env like below:
Or you can also add script in your package json file as well like below:
在 package.json 中,您可以将“start”脚本更改为
或者,您可以在项目的根目录中创建一个文件 .env 并设置:
如果您需要通过 HTTPS 运行应用程序,请执行以下操作:
In your package.json you can change the "start" script to
Or, you can create a file .env in the root of your project and set:
If you need to run you app over HTTPS, here is what to do:
如果您遇到错误“allowedHosts”为空:
您可以通过传递以下环境变量来禁用此检查:
If you're hitting an error 'allowedHosts' is empty:
You can disable this check by passing the following env variable: