Skip to main content
A WebSocket server typically needs to store some identifying information or context for each connected client. With Bun.serve(), set this “contextual data” by passing a data parameter to server.upgrade() when upgrading the connection.
server.ts

It’s common to read cookies/headers from the incoming request to identify the connecting client.
server.ts