【问题标题】: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?如果我部署我的 react 应用程序,到 localhost 的链接是否仍然有效,还是我还需要托管 localhost 应用程序?
【发布时间】:2021-02-20 13:49:02
【问题描述】:

基本上是标题。我在 localhost:1337 有一个 Strapi 应用程序,我将在 React 中获取它。我不太确定 localhost 是如何工作的,因此我想知道当我部署 react 应用程序时该路径是否仍然相关。

【问题讨论】:

    标签: reactjs deployment localhost next.js strapi


    【解决方案1】:

    当您在任何服务器上部署您的 react.js 应用程序时,您的 URL 名为 http://localhost:1337/Dashboard 将被改变。其中 http://localhost:1337/ 是基本 url 或域名。这会将服务器更改为新服务器。

    【讨论】:

    • 我不确定我是否遵循抱歉。这是否意味着 localhost:1337 仍然可以获取?或者一旦部署了 react 应用程序就会过时?
    • localhost:1337 将被淘汰,服务器将添加新域名
    • 哦,所以要获取的代码会自动切换到一个新的域名,然后一切都会正常工作吗?
    【解决方案2】:

    您的代码将为该 API 保持相同的值,并且每次更改 API 时都必须重新构建代码,(大多数人使用仅允许使用端口 80 的低成本托管服务提供商)我的建议是将您的端点(后端 url)移到 json、.env 文件中的代码之外……但是在大多数平台上起作用的是在您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-16
      • 1970-01-01
      • 2013-11-27
      相关资源
      最近更新 更多