Server Options
Basic Example
import { serve } from "sevok";
import { NodeRuntimeAdapter } from "sevok/node";
serve({
adapter: new NodeRuntimeAdapter(),
port: 3000,
hostname: "127.0.0.1",
routes: {
"/": () => new Response("hello"),
},
fetch: () => new Response("Not Found", { status: 404 }),
});
ServerInit
Server is constructed from ServerInit, which extends ServerOptions with
initialization-only fields such as adapter.
adapter
Optional runtime adapter used to integrate with Bun, Deno, Node.js, or a custom host.
import { BunRuntimeAdapter } from "sevok/bun";
adapter: new BunRuntimeAdapter();
If omitted, Server resolves a built-in adapter automatically for the current
runtime.
That means you usually only need to pass adapter when:
- you want to customize native Bun, Deno, or Node adapter options explicitly
- you want to force a specific runtime adapter instead of using auto-detection
- you are running outside the built-in Bun, Deno, or Node adapter targets
When adapter is omitted, Server lazily loads the matching built-in runtime
adapter with dynamic imports like import("sevok/bun"),
import("sevok/deno"), or import("sevok/node").
ServerOptions
routes
Declarative route table matched before fetch.
If routes does not include /*, fetch must be provided as a fallback.
Each path can point to either a single handler or a method map:
routes: {
"/users": {
GET: () => new Response("list"),
POST: () => new Response("create"),
"*": () => new Response("method fallback"),
},
}
When a method map is used, sevok resolves handlers in this order:
- explicit request method
GETforHEADrequests whenHEADis not defined*as a fallback for any remaining method
If a path matches but no handler matches the method, sevok returns 405 Method Not Allowed. The Allow header only includes explicitly declared
methods plus the inferred HEAD when GET exists.
fetch
Fallback request handler. When routes is omitted, it acts as the primary
request handler.
middleware
Global middleware array executed before the final handler.
middlewareResolver
Optional resolver for named middleware entries.
Use this when middleware contains strings such as "auth" instead of only
middleware functions. The resolver receives the middleware name and should
return the executable middleware function for that name.
If middlewareResolver is omitted, unresolved named middleware entries are
skipped. Throw from the resolver if unresolved names should fail the request.
error
Optional error handler that turns thrown exceptions or rejected promises into a
fallback Response.
error(error) {
return new Response(String(error), { status: 500 });
}
manual
When true, the server will not automatically call serve() during
construction.
port
Listening port. Defaults to PORT or 3000.
hostname
Listening host. Defaults to HOST or all interfaces.
reusePort
Ask the runtime to allow multiple processes to bind the same port when supported.
protocol
Use "http" or "https". If omitted, TLS configuration may still imply HTTPS.
tls
TLS certificate configuration. cert and key can be inline PEM strings or
filesystem paths.
tls: {
cert: "./certs/dev-cert.pem",
key: "./certs/dev-key.pem",
}
silent
Disable startup logging.
gracefulShutdown
Enable or configure process-signal shutdown handling.
gracefulShutdown: true
gracefulShutdown: {
gracefulTimeout: 5,
}
node
Node.js-specific native server options forwarded by NodeRuntimeAdapter during
setup().
node: {
http2: true,
requestTimeout: 30_000,
}
bun
Bun-specific options merged into Bun.serve().
BunServerOptions excludes fetch, routes, and unix, because sevok
owns request dispatch and currently binds through the generic hostname and
port options.
bun: {
idleTimeout: 10,
}
deno
Deno-specific Deno.ServeOptions merged into Deno.serve() during adapter
setup.
deno: {
signal: AbortSignal.timeout(30_000),
}