繁体   English   中英

如果我部署我的 React 应用程序,指向 localhost 的链接是否仍然有效,还是我还需要托管 localhost 应用程序?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM