Skip to main content
When building a WebSocket server, it’s typically necessary to store some identifying information or context associated with each connected client. With Bun.serve(), this “contextual data” is set when the connection is initially upgraded by passing a data parameter in the server.upgrade() call.
server.ts

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