配置代理:基础

  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

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐