mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
docs: update WebSockets example to use Bun.CookieMap (#19181)
This commit is contained in:
committed by
GitHub
parent
41388204b9
commit
512dee748b
@@ -117,14 +117,14 @@ type WebSocketData = {
|
||||
// TypeScript: specify the type of `data`
|
||||
Bun.serve<WebSocketData>({
|
||||
fetch(req, server) {
|
||||
// use a library to parse cookies
|
||||
const cookies = parseCookies(req.headers.get("Cookie"));
|
||||
const cookies = new Bun.CookieMap(req.headers.get("cookie")!);
|
||||
|
||||
server.upgrade(req, {
|
||||
// this object must conform to WebSocketData
|
||||
data: {
|
||||
createdAt: Date.now(),
|
||||
channelId: new URL(req.url).searchParams.get("channelId"),
|
||||
authToken: cookies["X-Token"],
|
||||
authToken: cookies.get("X-Token"),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user