aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-17 04:36:22 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-17 04:36:22 -0700
commitca02695993a3380a75ff4b19fb45814e184b092a (patch)
treef793877fb64ec45726946f40650c3b0928bf943e
parent9a2f2a94bf709a7f771b0fa2432cb2edbb8e9365 (diff)
downloadbun-ca02695993a3380a75ff4b19fb45814e184b092a.tar.gz
bun-ca02695993a3380a75ff4b19fb45814e184b092a.tar.zst
bun-ca02695993a3380a75ff4b19fb45814e184b092a.zip
Update README.md
-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);
+ },
},
});
```