How to avoid a hardcoded IP address in React JS

589 Views Asked by At

I have a React JS/Spring Boot app where the React JS part accesses the Spring Boot server URL via a link to get a report.

The problem is that, first, the IP address is hardcoded in React, and second, I have to swap the IP address to localhost when testing.

Here's the code:

  download() {
    // fake server request, getting the file url as response
    setTimeout(() => {
      const response = {
//        file: "http://1.1.1.1:9080/api/export",
        file: "http://localhost:8080/api/export",
      };
      // server sent the url to the file!
      // now, let's download:
      window.open(response.file);
    }, 100);
  }

How do I fix this issue?

0

There are 0 best solutions below