This commit is contained in:
Kevin Jahns 2024-03-26 13:18:21 +01:00
parent 7edbd8c3cb
commit af5c36d03a

View File

@ -20,15 +20,13 @@ const server = http.createServer((_request, response) => {
wss.on('connection', setupWSConnection) wss.on('connection', setupWSConnection)
server.on('upgrade', (request, socket, head) => { server.on('upgrade', (request, socket, head) => {
// You may check auth of request here.. // You may check auth of request here.. Call `wss.HandleUpgrade` *after* you
// checked whether the client has access (e.g. by checking cookies, or url
// parameters).
// See https://github.com/websockets/ws#client-authentication // See https://github.com/websockets/ws#client-authentication
/** wss.handleUpgrade(request, socket, head, /** @param {any} ws */ ws => {
* @param {any} ws
*/
const handleAuth = ws => {
wss.emit('connection', ws, request) wss.emit('connection', ws, request)
} })
wss.handleUpgrade(request, socket, head, handleAuth)
}) })
server.listen(port, host, () => { server.listen(port, host, () => {