Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy websockets connection within webpack-dev-server

Tags:

Is it possible to proxy websocket connections within the webpack dev server? I know how to proxy regular HTTP requests to another backend but it's not working for websockets, presumably because the target in the proxy configuration starts with http://...

like image 538
Martin Grůber Avatar asked Jul 27 '15 13:07

Martin Grůber


People also ask

Does webpack use Websockets?

1) webpack-dev-server can only proxy websocket connections, nothing more. 2) There is no requirement that you should split your server into a HTTP and WS parts. To use both in javascript you can use express-ws. This is also available in other languages (Spring supports it, Django also).

Can you proxy Websockets?

WebSocket over a Forward Proxy. WebSocket communication can take successfully take place in the presence of forward proxies, providing the client and proxy server have been configured properly to deal with it.

Do proxies support Websockets?

Today, most transparent proxy servers will not yet be familiar with the Web Socket protocol and these proxy servers will be unable to support the Web Socket protocol. In the future, however, proxy servers will likely become Web Sockets-aware and able to properly handle and forward WebSocket traffic.

What is webpack proxy?

webpack-dev-server can proxy some requests to others servers. This might be useful for developing API client when you want to send requests to same domain. Proxy is configured via proxy parameter.


1 Answers

Version 1.15.0 of the webpack-dev-server supports proxying websocket connections. Add the following to your configuration:

devServer: {   proxy: {     '/api': {        target: 'ws://[address]:[port]',        ws: true     },   }, } 
like image 166
Mr. Spice Avatar answered Sep 28 '22 12:09

Mr. Spice