lemonado
lemonado

Reputation: 93

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
  }
}

Upvotes: 9

Views: 4288

Answers (1)

Ahmed Musallam
Ahmed Musallam

Reputation: 9753

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
  }
}

Upvotes: 12

Related Questions