Skip to content
English

fallback

fallback(handler): Route

Defined in: src/http/Route.ts:198

Answer any request that matched no other route — the server-global not-found handler expressed in the DSL. Wired to the backend’s not-found hook at bind time, so it is method-agnostic (it also answers unmatched OPTIONS/HEAD) and MUST sit at the root of the tree: a fallback scoped under path() / pathPrefix() is rejected at compile time, because a server has exactly one not-found handler. At most one fallback() per server. It still composes with withMiddleware() / handleErrors(), which wrap its handler like any other, so a fallback can carry security headers or its own recovery.

concat(
path('api', apiRoutes),
fallback((request) => completeJson(Status.NotFound, { error: 'no route', path: request.path })),
)

(request) => HttpResponse | Promise<HttpResponse>

Route