Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular-CLI proxy to backend for WebSocket

It's perfectly working for Http, but not for WebSocket. I did not find the documentation about this. How can I do proxy for WS?

ng serve --proxy-config proxy.conf.json

proxy.conf.json:

{
  "/": {
    "target": "http://localhost:8080",
    "secure": false
  }
}
like image 593
lemonado Avatar asked Apr 25 '17 20:04

lemonado


1 Answers

Angular cli uses http-proxy-middleware for proxy under the hood. take a look at the documentation: https://github.com/chimurai/http-proxy-middleware

there is a websocket ws boolean option you can use as described in this section: https://github.com/chimurai/http-proxy-middleware#http-proxy-options

so you can change your config to:

{
  "/": {
    "target": "http://localhost:8080",
    "secure": false
    "ws":true
  }
}
like image 116
Ahmed Musallam Avatar answered Oct 28 '22 02:10

Ahmed Musallam