如何避免 React JS 中的硬编码 IP 地址

问题描述

我有一个 React JS/Spring Boot 应用程序,其中 React JS 部分通过链接访问 Spring Boot 服务器 URL 以获取报告。

问题在于,首先,IP 地址在 React 中是硬编码的,其次,我必须在测试时将 IP 地址交换为 localhost。

代码如下:

  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);
  }

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)