[英]If I deploy my react app, will the link to a localhost still be valid, or will I also need to host the localhost app?
基本上是標題。 我在 localhost:1337 有一個 Strapi 應用程序,我將在 React 中獲取它。 我不太確定 localhost 是如何工作的,因此我想知道在部署 React 應用程序時該路徑是否仍然相關。
當您在任何服務器上部署 react.js 應用程序時,名為 http://localhost:1337/Dashboard 的 url 將被更改。 其中 http://localhost:1337/ 是基本 URL 或域名。 這會將服務器更改為新服務器。
您的代碼將為該 API 保持相同的價值,每次更改 API 時,您都必須重新構建代碼,(大多數人使用低成本的托管服務提供商,只允許使用端口 80)我的建議是移動您的在 json、.env 文件中的代碼之外的端點(后端 url)……但是在大多數平台上可以使用的是 public/index.html 中定義的變量(不是最佳實踐,但可以使用)例如:
<html>
<head>
<!-- you will add this tag here it will contain your backend url -->
<script>
var bakendUrl = "http://....";
</script>
<!-- some other code here -->
</head>
<body>
<div id="root"></div>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.