Server Options
Basic Example
import { serve } from "@hornjs/fest";
import { NodeRuntimeAdapter } from "@hornjs/fest/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 and plugins.
adapter
Optional runtime adapter used to integrate with Bun, Deno, Node.js, or a custom host.
import { BunRuntimeAdapter } from "@hornjs/fest/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("@hornjs/fest/bun"),
import("@hornjs/fest/deno"), or import("@hornjs/fest/node").
plugins
Optional ServerPlugin[] hooks that can mutate the server instance during
construction before the adapter is set up.
ServerOptions
routes
Declarative route table matched before fetch.
If routes does not include /*, fetch must be provided as a fallback.
fetch
Fallback request handler. When routes is omitted, it acts as the primary
request handler.
middleware
Global middleware array executed before the final handler.
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,
}