/** * Core functionality to create an HTTP server from a router. * * @see {@link serve} * @packageDocumentation */ import type { AddressInfo } from "node:net"; import type { HttpService } from "../service/index.js"; /** * Configuration options for starting a server. */ export type ServeConfig = { /** * Port to run the server on. * * Defaults to random available port. */ port?: number | undefined; /** * Hostname to bind the server to. * * Defaults to not specific binding. */ hostname?: string | undefined; /** * Whether to trust proxy headers. * * When set to true, `forwarded-for-*` headers will be considered. */ trustProxy?: boolean; /** * Signal to shut down the server. */ abortSignal?: AbortSignal; /** * Catches `CTRL+C` and shuts down the server gracefully. */ catchCtrlC?: boolean; /** * Maximum time (in milliseconds) to wait before returning. * * This will `unref` the server once the timeout expired and return early. The server will still be open until your * program exits. */ shutdownTimeout?: number; /** * Starts the server in `unref`ed mode. * * This is primarily useful in test environments so that an unclosed server doesn't prevent your tests from * existing. */ unrefOnStart?: boolean; /** * Called once the server started listening. */ onListen?: (address: AddressInfo) => void; }; /** * Serve any service via HTTP. * * This method of running a service is intentionally simple and only supports * the minimally required configuration. If you need to support HTTPS and/or * HTTP2, you should create your own listener. In most cases this should not be * required, as TLS termination and HTTP2 are usually handled by a reverse proxy * in production. * * @example * ```ts * const router = new Router() * .route("/", get(() => HttpResponse.builder().raw("Hello world!")); * * await serve(router, { * port: 8080, * catchCtrlC: true, * shutdownTimeout: 3000, * }); * ``` */ export declare const serve: (service: HttpService, config?: ServeConfig) => Promise;