--- name: Upgrade an HTTP request to a WebSocket connection --- Inside `fetch`, use the `server.upgrade()` function to upgrade an incoming `Request` to a WebSocket connection. Bun automatically returns a 101 Switching Protocols response if the upgrade succeeds. Refer to the [WebSocket docs](/docs/api/websockets) for more information on building WebSocket servers. ```ts const server = Bun.serve<{ authToken: string }>({ fetch(req, server) { const success = server.upgrade(req); if (success) { // Bun automatically returns a 101 Switching Protocols // if the upgrade succeeds return undefined; } // handle HTTP request normally return new Response("Hello world!"); }, websocket: { // define websocket handlers }, }); console.log(`Listening on localhost:\${server.port}`); ``` /system-store'>ansg191/system-store Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/ffi.test.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-06-05wipGravatar Jarred Sumner 5-129/+241
2023-06-04wipGravatar Jarred Sumner 3-54/+44
2023-06-04fix some CLI thingsGravatar Jarred Sumner 1-8/+13
2023-06-04fixupGravatar Jarred Sumner 4-3/+4
2023-06-04Fix buildGravatar Jarred Sumner 1-1/+2
2023-06-04Add types and sample heapsnapshot for JSC and V8Gravatar Ashcon Partovi 4-0/+48475