用了http://vuejs-templates.github.io/webpack/proxy.html 这个方案,还是不行(我访问的是另外一台机器的端口)。而且config.js里面proxyTable格式是固定的,我需要怎么正确配置才能跨域;
proxyTable: {
       '*': 'http://192.168.1.30:7122'
}
我也没有找到如何开启ws的方案;
用了https://www.npmjs.com/package/http-proxy-middleware 插件下的配置方式书写,就报错;
@EvanHunt I'm pretty sure issue belongs here: https://github.com/vuejs-templates/webpack
Anyways, to configure proxy middleware you can change options object before it's used here: https://github.com/vuejs-templates/webpack/blob/dist/template/build/dev-server.js#L42
WebSocket options for http-proxy-middleware are defined here: https://github.com/chimurai/http-proxy-middleware#websocket
@zigomir tks, I'll take a look at API.
@evanhunt 你好 我想问一下最后是怎么在proxyTable中设置的websocket连接 我也遇到了这样的问题 谢谢
@smilebuz  抱歉今天才注意到,
vue-cli中代理用的是 http-proxy-middleware 插件
你可以去 https://github.com/chimurai/http-proxy-middleware#websocket看示例代码
设置 websocket 只需要开启配置就行了
...
proxyTable: {
     '/api': {
         target: `http:${host}:${port}`,
         changeOring: true,
         ws: true,
     }
},
...
Websocket request is able to cross domains. Why is proxy needed for it?
Most helpful comment
@smilebuz 抱歉今天才注意到,
vue-cli中代理用的是http-proxy-middleware插件你可以去
https://github.com/chimurai/http-proxy-middleware#websocket看示例代码设置
websocket只需要开启配置就行了