webpack proxyTable 代理多个target地址,应该如何设置?

我要请求的服务器A接口 为A
http://192.168.0.106:8080/qianbomall/app/login
服务器B的接口
http://pv.sohu.com/cityjson

现在我设置ProxyTable

proxyTable: [{
  '/api': {
    target: 'http://192.168.0.106:8080',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }
},{
'/ips': {
    target: 'http://pv.sohu.com',
    changeOrigin: true,
    pathRewrite: {
      '^/ips': ''
    }
  }
}]

接口请求的时候,

axios.get('ips/cityjson')
axios.post('api/qianbomall/app/login')

请求直接把index.html给我返回了

如果 只设置一个代理的话是没有问题的,请问我是不是写法有问题

proxyTable: {
  '/api': {
    target: 'http://192.168.0.106:8080',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }
}
阅读 8.3k
2 个回答
proxyTable: {
  '/api': {
    target: 'http://192.168.0.106:8080',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  },
'/ips': {
    target: 'http://pv.sohu.com',
    changeOrigin: true,
    pathRewrite: {
      '^/ips': ''
    }
  }
}

没问题 看看报什么错了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进