Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

express如何接收websocket请求

$
0
0

项目情况:

  1. 前端使用 actioncable 发送 socket到node端。
ActionCable.createConsumer(`ws://${location.hostname}:8000/cable`)
  1. node 使用 http-proxy-middleware 转发 socket请求。
app.use('/cable', proxy({ target: proxyTarget, changeOrigin: true, ws: true, }))
  1. rails 后端接收 node发送的请求。

但是前端发送的socket报错

WebSocket connection to 'ws://127.0.0.1:8000/cable' failed: Connection closed before receiving a handshake response

node没有接收到任何请求,日志没有记录。

想问一下,怎么弄转发。


Viewing all articles
Browse latest Browse all 14821

Trending Articles