配置代理:基础

  devServer: {
    proxy: {
      // 配置多个代理(配置一个 proxy: 'http://localhost:4000' // 本地模拟数据服务器)
      "^/v1": {
        target: "https://monitor-api.xxx", //
        ws: true,
        changeOrigin: true,
      },
"/d": {
        target: "https://monitor-third-pard-api.xxx", //431
        ws: true,
        changeOrigin: true
      },
      "^/api": {
        target: "https://monitor-third-pard-api.xxx", //431
        ws: true,
        changeOrigin: true
      },
      "/login": {
        target: "https://monitor-third-pard-api.xxx", //431
        ws: true,
        changeOrigin: true
      },
      "/public": {
        target: "https://monitor-third-pard-api.xxx", //431
        ws: true,
        changeOrigin: true
      }
    }
  },

配置代理的时候可以通过以上方式,但是当多个路径使用同一个代理的时候,按上述方式就有点不简洁,网上搜了一遍都没有找到合适的说明,最后尝试了一下,发现以下方式可行

配置代理:优化

  devServer: {
    proxy: {
      // 配置多个代理(配置一个 proxy: 'http://localhost:4000' // 本地模拟数据服务器)
      "^/v1": {
        target: "https://monitor-api.xxx", //
        ws: true,
        changeOrigin: true,
      },
       "^/(d|api|login|public)/" : {
        target: ""https://monitor-third-pard-api.xxx", //431
        ws: true,
        changeOrigin: true
      }
    }
  },
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐