Skip to content

default

default(options?): object

Defined in: router.js:84

Create a new Ergo router instance.

Function

Default catch handler for all route pipelines

boolean

Enable pipeline debug tracing. When true, responseAcc._trace is initialized per request with {steps, breakAt}.

object

Default middleware config for declarative routes. Each key corresponds to a pipeline stage (e.g. accepts, cookie, timeout). Route-level config overrides these. Set a key to false to disable by default.

Function

Router-level observation hook. Fires on every response: both pipeline-routed responses (after send()) and transport-level short-circuits (404, 405, 415, 429, OPTIONS, CORS preflight). For pipeline responses, route-level hooks fire first, then the router-level hook. Receives (req, res, responseInfo, domainAcc) where domainAcc is undefined for transport-level responses (no pipeline ran). responseInfo.source is 'pipeline' or 'transport'. Hook errors are swallowed.

Set<string>

Header names to replace with '[REDACTED]' in responseInfo.headers passed to onResponse hooks. Defaults to DEFAULT_REDACTED_HEADERS (authorization, proxy-authorization, cookie, set-cookie). Pass an empty Set to disable redaction. Route-level redactHeaders overrides this.

object

Default send() options applied to all routes

boolean

If true, throw on unknown config keys; if false, warn

boolean

Enforce Content-Type on POST/PUT requests

boolean

Enforce Content-Type on PATCH requests

boolean | object

Inject an X-Response-Time header measuring pipeline execution time. Pass true for defaults (x-response-time, 3 decimal places), or {header?: string, precision?: number} for custom configuration. Zero overhead when disabled.

object

Transport-layer config (requestId, security, rateLimit, cors)

_dispatcher: Instance<V1> = dispatcher

_middleware: any[] = appMiddleware

_options: object = options

optional catchHandler?: Function

optional debug?: boolean

optional defaults?: object

optional onResponse?: Function

optional redactHeaders?: Set<string>

optional send?: object

optional strict?: boolean

optional strictBody?: boolean

optional strictPatch?: boolean

optional timing?: boolean | object

optional transport?: object

_pathIndex: Instance<V1> = pathIndex

_redactSet: Set<string> = redactSet

_registry: MethodRegistry = registry

_routes: object[] = routes

_subRouters: any[] = subRouters

_transport: { run: { requestId: string | undefined; stop: boolean; }; } | undefined = transport

{ run: { requestId: string | undefined; stop: boolean; }; }

run(req, res, allowedMethods?): object

Run the transport layer on a request.

object

HTTP request

object

HTTP response

Set<string>

Registered methods for this path

object

stop=true means the response has been sent (preflight, rate limited)

requestId: string | undefined

stop: boolean


undefined

_wrap: (pipeline, routeOpts?) => Function = wrapPipeline

Function | Function[]

Function

boolean

Function

Set<string>

object

Function

delete(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Register a DELETE route.

string

URL pattern (e.g. ‘/users/:id’)

Function | Function[] | RouteConfig

Handler function, pipeline array, or declarative config object

object

Per-route options (validated and merged for all pipeline types)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

get(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Register a GET route.

string

URL pattern (e.g. ‘/users/:id’)

Function | Function[] | RouteConfig

Handler function, pipeline array, or declarative config object

object

Per-route options (validated and merged for all pipeline types)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

handle(): (req, res) => any

Create the Node.js HTTP request handler.

(req, res) => any

listen(port, …args): Server<typeof IncomingMessage, typeof ServerResponse>

Convenience: create an HTTP server and start listening.

number

any[]

Additional arguments passed to server.listen()

Server<typeof IncomingMessage, typeof ServerResponse>

mount(prefix, subRouter): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Mount a sub-router at a prefix path.

string

URL prefix (e.g. ‘/api/v1’)

object

Another router instance

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

patch(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Register a PATCH route.

string

URL pattern (e.g. ‘/users/:id’)

Function | Function[] | RouteConfig

Handler function, pipeline array, or declarative config object

object

Per-route options (validated and merged for all pipeline types)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

post(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Register a POST route.

string

URL pattern (e.g. ‘/users’)

Function | Function[] | RouteConfig

Handler function, pipeline array, or declarative config object

object

Per-route options (validated and merged for all pipeline types)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

put(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Register a PUT route.

string

URL pattern (e.g. ‘/users/:id’)

Function | Function[] | RouteConfig

Handler function, pipeline array, or declarative config object

object

Per-route options (validated and merged for all pipeline types)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

routeTable(): string

Return a formatted route table string summarizing registered routes, enabled middleware, and transport configuration.

string

  • Multi-line route table suitable for logging at startup

use(…fns): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }

Add application-level middleware that runs before every route pipeline.

Function[]

Middleware functions

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 15 more …; routeTable(): string; }