[英]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?
Basically the heading.基本上是标题。 I have a strapi app at localhost:1337 which I will fetch in React.
我在 localhost:1337 有一个 Strapi 应用程序,我将在 React 中获取它。 I'm not very sure how localhost works, and therefore I want to know if the path will still be relevant when I deploy the react app.
我不太确定 localhost 是如何工作的,因此我想知道在部署 React 应用程序时该路径是否仍然相关。
When you deploy your react.js app on any server your url named http://localhost:1337/Dashboard will be changed.当您在任何服务器上部署 react.js 应用程序时,名为 http://localhost:1337/Dashboard 的 url 将被更改。 In it http://localhost:1337/ is the base url or domain name.
其中 http://localhost:1337/ 是基本 URL 或域名。 Which will change the server to the new one.
这会将服务器更改为新服务器。
your code will maintain same value for that API and you will have to re-build your code each time you change your API, (most of people use low cost hosting provider which allow only port 80 to be used) my advice is to move your endpoit (backend url) outside your code in a json, .env file ... but what will work on most of platform is a variable defined in your public/index.html (not a best pratice but it will work) ex:您的代码将为该 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.