add tips for handling auth and add typings for ws

This commit is contained in:
Kevin Jahns
2024-03-27 16:10:00 +01:00
parent af5c36d03a
commit 7945a5ba12
3 changed files with 14 additions and 6 deletions

View File

@@ -1,8 +1,5 @@
#!/usr/bin/env node
/**
* @type {any}
*/
const WebSocket = require('ws')
const http = require('http')
const number = require('lib0/number')
@@ -20,9 +17,9 @@ const server = http.createServer((_request, response) => {
wss.on('connection', setupWSConnection)
server.on('upgrade', (request, socket, head) => {
// 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).
// 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
wss.handleUpgrade(request, socket, head, /** @param {any} ws */ ws => {
wss.emit('connection', ws, request)