Proxy websockets connection within webpack-dev-server

前端 未结 3 1735
渐次进展
渐次进展 2021-02-12 20:47

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

3条回答
  •  误落风尘
    2021-02-12 21:29

    @Mr. Spice's answer is correct. But it can be further simplified, check http-proxy-middleware, it can be set as following, i.e. just add ws: true and keep other settings as usual.

    // proxy middleware options
    var options = {
            target: 'http://www.example.org', // target host
            changeOrigin: true,               // needed for virtual hosted sites
            ws: true,                         // proxy websockets
            ...
    

提交回复
热议问题