uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.85k stars 570 forks source link

How to get url in open or message event in ws #451

Closed robert-bitguild closed 3 years ago

robert-bitguild commented 3 years ago

Hi,

I can't get the ws url in open or message event. I think it should easy to fetch the url of ws like ws://localhost/abc?abc=xxxx

app.ws('/*', { // config compression: uWS.SHARED_COMPRESSOR, maxPayloadLength: MAX_PAY_LOAD_LENGTH, // 最大传输字节数 1k idleTimeout: IDLE_TIMEOUT, // 心跳间隔

open: (ws, req) => {
  console.log("123123123123");
  ConnectHandler.handle(ws);
},

message: (ws, message, isBinary, ...params) => {
  MessageHandler.handle(app, ws, message);
},

close: (ws, code, message) => {
  CloseHandler.handle(app, ws, SOCKETS);
}

// }); });

The req object in open event is always undefined.

Thanks

ghost commented 3 years ago

https://github.com/uNetworking/uWebSockets.js/blob/master/examples/Upgrade.js