notFound() / useMethodNotAllowed()
app.notFound(handler?)
Section titled “app.notFound(handler?)”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"));| Parameter | Type | Default | Description |
|---|---|---|---|
handler | RequestHandler | JSON default | Optional custom handler |
Returns
Section titled “Returns”KaelumApp — the app instance for chaining.
app.useMethodNotAllowed(options?)
Section titled “app.useMethodNotAllowed(options?)”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 }); }});| Parameter | Type | Default | Description |
|---|---|---|---|
options.handler | Function | JSON default | Optional handler function (req, res, allowedMethods) => void |
Returns
Section titled “Returns”KaelumApp — the app instance for chaining.
MethodNotAllowedOptions
Section titled “MethodNotAllowedOptions”interface MethodNotAllowedOptions { handler?: (req: Request, res: Response, allowedMethods: string[]) => any;}