aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
1 files changed, 11 insertions, 3 deletions
diff --git a/README.md b/README.md
index 69b6ef9e4..6cb749d3f 100644
--- a/README.md
+++ b/README.md
@@ -2265,9 +2265,17 @@ For server websocket connections, Bun exposes a `ServerWebSocket` class which is
`ServerWebSocket` supports passing headers. This is useful for setting cookies or other headers that you want to send to the client before the connection is upgraded.
```ts
-server.upgrade(req, {
- headers: {
- "Set-Cookie": "name=" + new URL(req.url).searchParams.get("name"),
+Bun.serve({
+ fetch(req, server) {
+ if (
+ server.upgrade(req, { headers: { "Set-Cookie": "name=HiThereMyNameIs" } })
+ )
+ return;
+ },
+ websocket: {
+ message(ws, message) {
+ ws.send(message);
+ },
},
});
```