Skip to content

Commit

Permalink
add tips for handling auth and add typings for ws
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 27, 2024
1 parent af5c36d commit 7945a5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 3 additions & 6 deletions bin/server.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env node

/**
* @type {any}
*/
const WebSocket = require('ws')
const http = require('http')
const number = require('lib0/number')
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"devDependencies": {
"@types/node": "^18.15.0",
"@types/ws": "^8.5.10",
"rollup": "^3.19.1",
"standard": "^12.0.1",
"typescript": "^4.9.5",
Expand Down

0 comments on commit 7945a5b

Please sign in to comment.