Skip to content

请问如何实现代理解决跨域问题,然后怎么开启websocket #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gaofant101 opened this issue Jul 12, 2016 · 5 comments
Closed

Comments

@gaofant101
Copy link

用了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 插件下的配置方式书写,就报错;

@zigomir
Copy link
Contributor

zigomir commented Jul 12, 2016

@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 zigomir closed this as completed Jul 12, 2016
@gaofant101
Copy link
Author

gaofant101 commented Jul 13, 2016

@zigomir tks, I'll take a look at API.

@smilebuz
Copy link

@EvanHunt 你好 我想问一下最后是怎么在proxyTable中设置的websocket连接 我也遇到了这样的问题 谢谢

@gaofant101
Copy link
Author

@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,
     }
},
...

@Yakima-Teng
Copy link

Websocket request is able to cross domains. Why is proxy needed for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants