Vue-cli: dev-server中的proxyTable如何配置才能正确转发ajax请求呢?

Created on 15 Mar 2016  ·  10Comments  ·  Source: vuejs/vue-cli

发现如何配置都不会被转发。

var proxyTable = {
  '/v4': 'http://121.41.108.245:8899/yuntujinfu-wap'
}
// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context];
  if (typeof options === 'string') {
    options = {target: options, changeOrigin: true}
  }
  app.use(proxyMiddleware(context, options))
})

module.exports = app.listen(4001, function (err) {
  if (err) {
    console.log(err)
    return
  }
  console.log('Listening at http://localhost:4001')
})

Update: 发现把app.use(proxy) 放在比较靠前的位置才会生效

Most helpful comment

我也遇到了,现在还是转发不了。

All 10 comments

嗯,已经修正了,要把 proxy middleware 提到最前。

然而并没有什么用还是遇到了这个问题

我也遇到了,现在还是转发不了。

执行post 和get 可以,再是执行delete和put时遇到点问题

这个问题怎么解决的,还是转发不了

转发不了。

是不是因为target配置问题
'/v4': 'http://121.41.108.245:8899/yuntujinfu-wap'
后面不需要/yuntujinfu-wap

@WLyKan /yuntujinfu-wap 是我们 tomcat 的 context,必须要的。

楼上为啥都转发不了呢。

楼上你们看看这个插件的用法啊,小尤回答的问题是这个插件跟vue-cli结合的时候没写好的问题,具体配置和使用看这里https://github.com/chimurai/http-proxy-middleware

请求地址 => target: 'http://183.192.191.12:1000',
单个请求接口 => return axios.post('/copyrightmanagementservice/systemConfig/add', params );
请问我在config/index.js 怎么配置proxyTable ,谢谢!
@yyx990803 @lmnsg

Was this page helpful?
0 / 5 - 0 ratings