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