In version 3.0.0 the WebSocket.upgradeReq property has been removed. Unfortunately that means that now there's no simple way to determine on the server which URL the client originally requested. In version 2.3.1 you could do this simply using ws.upgradeReq.url where ws is the instance of the WebSocket class.
version: 3.0.0
Node.js version(s): any
OS version(s): any
N/A
N/A
N/A
N/A
You can save it when the connection event is emitted:
wss.on('connection', function connection(ws, req) {
const url = req.url;
// Do whatever you want with it.
// You can even reattach it to the `ws` object if you need to.
});
Great, I didn't see this possibility, many thanks for the hint!
ws.url=req.url
@Globik using ws.url will return undefined for me with version 3.2.1.
@cre8
Yes, it should be.
Please use req.url from second parameter.
Most helpful comment
You can save it when the
connectionevent is emitted: