Using Express + ws (websocket) libraries.
"App" uses some Express middleware to add the current user to the request object, but WS gets a Node request object without the information I need.
How can I pass this data to the websocket when upgrading connection?
const server = http.createServer(app); // app is using the express middleware to add info I need
const wss: WebSocket.Server = new WebSocketService(clients, { noServer: true }).wss;
server.on('upgrade', (request, socket: any, head) => {
wss.handleUpgrade(request, socket, head, (ws: WebSocket) => {
wss.emit('connection', ws, request);
});
});
server.listen(3000, () => {
console.log('Listening on port 3000');
});