🚀 Enhancements
createWebSocketProxy util (#184)
New createWebSocketProxy util returns crossws hooks that forward every incoming peer to an upstream ws:// or wss:// target. Text and binary messages, close, and error events are relayed bi-directionally, and client messages sent before the upstream is ready are buffered (up to a configurable maxBufferSize) and flushed once connected.
import crossws from "crossws/adapters/<adapter>";
import { createWebSocketProxy } from "crossws";
const ws = crossws({
hooks: createWebSocketProxy("wss://echo.websocket.org"),
});The target can also be a (peer) => url resolver for dynamic routing, and the returned hooks can be extended (for auth, logging, header forwarding, etc.) like any other crossws hooks. See the proxy guide for auth, dynamic targets, and SSRF hardening notes.
fromNodeUpgradeHandler util + socket.io support (#185)
New fromNodeUpgradeHandler util (exported from crossws/adapters/node) wraps a plain Node.js (req, socket, head) upgrade handler as a crossws hooks object. This makes it possible to mount existing ws, socket.io, or express-ws based WebSocket servers through the Node adapter while they keep full ownership of the socket lifecycle.
import { WebSocketServer } from "ws";
import { fromNodeUpgradeHandler } from "crossws/adapters/node";
import { serve } from "crossws/server/node";
const wss = new WebSocketServer({ noServer: true });
wss.on("connection", (ws) => {
ws.on("message", (data) => ws.send(data));
});
serve({
fetch: () => new Response("ok"),
websocket: fromNodeUpgradeHandler((req, socket, head) => {
wss.handleUpgrade(req, socket, head, (ws) => {
wss.emit("connection", ws, req);
});
}),
});Because the wrapped handler takes ownership of the socket, crossws lifecycle hooks (open/message/close/error) are not invoked for connections routed through it — the underlying library manages them. A full socket.io example combining WebSocket and HTTP long-polling transports is included in the repo.
Other
- New
bunnyadapter (#179)
🩹 Fixes
- node: Do not url-encode upgrade response headers (ffbed40)
📦 Build
- Export
ServerWithWSOptionsandWSOptionstypes (#180)
🏡 Chore
- Update deps (ae08ca9)
- Update deps (3d83ed0)
- Update undici in tests (6291e7c)
- Migrate to oxlint and oxfmt (6a1a257)
- Update docs (02427f9)
✅ Tests
- node: Add regression test for
EADDRINUSEhandling (#183)
❤️ Contributors
- Pooya Parsa (@pi0)
- Neko (@nekomeowww)
- Sandro Circi (@sandros94)