diff options
author | 2022-10-17 04:36:22 -0700 | |
---|---|---|
committer | 2022-10-17 04:36:22 -0700 | |
commit | ca02695993a3380a75ff4b19fb45814e184b092a (patch) | |
tree | f793877fb64ec45726946f40650c3b0928bf943e | |
parent | 9a2f2a94bf709a7f771b0fa2432cb2edbb8e9365 (diff) | |
download | bun-ca02695993a3380a75ff4b19fb45814e184b092a.tar.gz bun-ca02695993a3380a75ff4b19fb45814e184b092a.tar.zst bun-ca02695993a3380a75ff4b19fb45814e184b092a.zip |
Update README.md
-rw-r--r-- | README.md | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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); + }, }, }); ``` |