Supported runtimes
How to run Zen Router on Cloudflare Workers, Bun, and other runtimes.
Both ZenRouter and ZenRelay expose a .fetch method that is a standard
(request: Request) => Promise<Response> handler. This makes them compatible
with any runtime that supports the Web Request/Response API.
Cloudflare Workers
Simple! Just export the router as the default export. Cloudflare Workers calls
.fetch automatically.
importfrom "@liveblocks/zenrouter";
const zen = new ZenRouter...
zen.route"GET /api/health", () =>"ok"
zen.route"GET /api/posts/<postId>", asyncp=>...
zen.route"POST /api/posts", bodySchema, asyncbody=>...
// Just use a default export in your worker file
export defaultBun
Simple! Just pass .fetch to Bun.serve():
importfrom "@liveblocks/zenrouter";
const zen = new ZenRouter...
zen.route"GET /api/health", () =>"ok"
zen.route"GET /api/posts/<postId>", asyncp=>...
zen.route"POST /api/posts", bodySchema, asyncbody=>...
// Pass zen.fetch to Bun.serve()
Bun.serve8000Node.js
Node.js uses IncomingMessage/ServerResponse instead of the Web
Request/Response API, so you need an adapter. We recommend
@whatwg-node/server:
importfrom "node:http";
importfrom "@whatwg-node/server";
importfrom "@liveblocks/zenrouter";
const zen = new ZenRouter...
zen.route"GET /api/health", () =>"ok"
zen.route"GET /api/posts/<postId>", asyncp=>...
zen.route"POST /api/posts", bodySchema, asyncbody=>...
const server = createServercreateServerAdapter
server.listen8000