简体   繁体   中英

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. 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.

When you deploy your react.js app on any server your url named http://localhost:1337/Dashboard will be changed. In it http://localhost:1337/ is the base url or domain name. 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:

  <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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