umijs服务器代理配置,多个代理

发布时间 2023-03-22 21:09:30作者: herry菌

同时代理api和资源:

//服务器代理
  proxy: {
    '/api': {
      target: 'http://xxx',
      changeOrigin: true,
      pathRewrite: {
        '^/api/': '/api/',
      },
    },
    //media资源代理
    '/media': {
      target: 'http://xxx',
      changeOrigin: true,
      pathRewrite: {
        '^/media': '/media',
      },
    },
  },

即可实现访问http://localhost/api/*http://localhost/media/*时跳转到指定到http://xxx/api/*http://xxx/media/*