Skip to content

notFound() / useMethodNotAllowed()

Registers a catch-all 404 Not Found middleware. Must be registered after all your routes.

app.notFound();
app.notFound((req, res) => res.status(404).send("Page not found"));
ParameterTypeDefaultDescription
handlerRequestHandlerJSON defaultOptional custom handler

KaelumApp — the app instance for chaining.


Intercepts requests where the path exists, but the HTTP method doesn’t, returning a 405 Method Not Allowed with the Allow header populated with the accepted methods.

Must be registered after your routes and before app.notFound().

app.useMethodNotAllowed();
app.useMethodNotAllowed({
handler: (req, res, allowedMethods) => {
res.status(405).json({ allowed: allowedMethods });
}
});
ParameterTypeDefaultDescription
options.handlerFunctionJSON defaultOptional handler function (req, res, allowedMethods) => void

KaelumApp — the app instance for chaining.


interface MethodNotAllowedOptions {
handler?: (req: Request, res: Response, allowedMethods: string[]) => any;
}