webpack-dev-server 中的代理 websockets 连接 [英] Proxy websockets connection within webpack-dev-server

查看:188
本文介绍了webpack-dev-server 中的代理 websockets 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 webpack 开发服务器中代理 websocket 连接?我知道如何将常规 HTTP 请求代理到另一个后端,但它不适用于 websockets,大概是因为代理配置中的目标以 http://... 开头

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

推荐答案

1.15.0 版的 webpack-dev-server 支持代理 websocket 连接.将以下内容添加到您的配置中:

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

这篇关于webpack-dev-server 中的代理 websockets 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆