Bun Runtime
Basic Usage
import { serve } from "sevo";
import { BunRuntimeAdapter } from "sevo/bun";
serve({
adapter: new BunRuntimeAdapter(),
routes: {
"/": () => new Response("Hello from Bun"),
},
fetch: () => new Response("Not Found", { status: 404 }),
});
Runtime-Specific Server Options
Use ServerOptions.bun to forward Bun-native options through
BunRuntimeAdapter.
BunServerOptions is defined as:
type BunServerOptions = Omit<Bun.Serve.Options<any>, "fetch" | "routes" | "unix">;
fetch, routes, and unix are excluded because Server owns request
dispatch and sevo currently binds through the generic hostname / port
options instead.
Pass Bun-native options on the bun field:
serve({
adapter: new BunRuntimeAdapter(),
bun: {
idleTimeout: 10,
},
fetch() {
return new Response("Hello from Bun");
},
});
Commonly Used Options
idleTimeout: close idle connections after a number of secondshostname: override the listening hostnameport: override the listening porttls: pass Bun-specific TLS optionserror: customize Bun's runtime-level error handling
Official References
- Bun HTTP server docs: https://bun.sh/docs/runtime/http/server
What the Adapter Does
BunRuntimeAdapter translates generic ServerOptions into Bun's native
listener options and delegates request handling through server.fetch().
It is responsible for:
- resolving
hostnameandport - applying
reusePort - wiring the runtime
errorhandler - merging TLS options into Bun's
tlsfield - reporting the final listening URL
TLS
When TLS is configured on the server, BunRuntimeAdapter resolves certificate
and key values from either inline PEM strings or filesystem paths.
serve({
adapter: new BunRuntimeAdapter(),
protocol: "https",
tls: {
cert: "./certs/dev-cert.pem",
key: "./certs/dev-key.pem",
},
routes: {
"/": () => new Response("secure"),
},
fetch: () => new Response("Not Found", { status: 404 }),
});
URL Resolution
The adapter exposes Bun's resolved server.url.href as server.url.
CLI Usage
When using the CLI under Bun:
bunx --bun sevo
You can also preload modules with Bun's --import support through the CLI:
sevo --entry ./server.tsx --import jiti/register