Proxy websockets connection within webpack-dev-server

Martin Grůber picture Martin Grůber · Jul 27, 2015 · Viewed 15.6k times · Source

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://...

Answer

Mr. Spice picture Mr. Spice · Aug 30, 2016

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