Skip to content

ServerOptions ​

ServerOptions configures the listener passed to app.listen(...). Pass the options as an object, either inline or through a value typed as ServerOptions.

Signatureinterface ServerOptions

Settings ​

SettingPurpose
hostIP address to bind. Defaults to all interfaces.
requestTimeoutMaximum time for a request, including its body and handler. Expired requests receive 503.
maxConcurrentRequestsMaximum number of requests running at once. Additional requests wait for a permit and remain bounded by requestTimeout.
maxConnectionsMaximum number of open connections. It is unset by default; when reached, the server stops accepting connections.
shutdownTimeoutMaximum time to wait for active requests during shutdown.
loggerWrites one structured access event per completed response to stderr when true; defaults to false.
headerTimeoutMaximum time to receive request headers. Defaults to 10 seconds and cannot be disabled.
maxHeaderSizeMaximum combined request-line and header size. Defaults to 64 KiB and has a minimum of 8 KiB.
keepAliveAllows a connection to carry multiple requests. Enabled by default.
tlsServes HTTPS with the configured certificate and private key. Both are required.

rateLimit is configured on the router with app.rateLimit(...), not in ServerOptions. Header limits apply before a route runs, while requestTimeout covers a request after its headers arrive.

Example ​

tyrus
import { createRouter, HttpError, HttpRouter, ServerOptions } from "tyrus:http";

const app: HttpRouter = createRouter();
const options: ServerOptions = {
    host: "127.0.0.1",
    requestTimeout: "30s",
    maxConcurrentRequests: 1024,
    maxConnections: 4096,
    shutdownTimeout: "10s",
    logger: true,
};

try {
    app.listen(3000, options);
} catch (error: HttpError) {
    printError(`${error.code}: ${error.message}`);
}