Skip to content

default

default(options?): object

Defined in: router.js:62

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.

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 send?: object

optional strict?: boolean

optional strictBody?: boolean

optional strictPatch?: boolean

optional timing?: boolean | object

optional transport?: object

_pathIndex: Instance<V1> = pathIndex

_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

object

Function

delete(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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 (only for function/array pipelines)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

get(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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 (only for function/array pipelines)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

patch(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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 (only for function/array pipelines)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

post(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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 (only for function/array pipelines)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

put(path, pipeline, routeOpts?): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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 (only for function/array pipelines)

{ _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

use(…fns): { _dispatcher: Instance<HTTPVersion.V1>; _pathIndex: Instance<HTTPVersion.V1>; _registry: MethodRegistry; _middleware: any[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }

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[]; … 13 more …; delete(path: string, pipeline: Function | … 1 more … | RouteConfig, routeOpts?: object | undefined): …; }