feat: support overwriting default 404 handler (#3081)

Fixes https://github.com/denoland/fresh/issues/1918
This commit is contained in:
Marvin Hagemeister
2025-07-09 00:40:12 +02:00
committed by GitHub
parent ec2bb17589
commit 0b3546f201
2 changed files with 20 additions and 2 deletions
+8 -2
View File
@@ -242,7 +242,13 @@ export class App<State> {
return this;
}
handler(): (
/**
* Create handler function for `Deno.serve` or to be used in
* testing.
* @param {() => Promise<Response>} [nextFn] overwrite default 404 handler
* @returns {Deno.ServeHandler}
*/
handler(nextFn?: () => Promise<Response>): (
request: Request,
info?: Deno.ServeHandlerInfo,
) => Promise<Response> {
@@ -273,7 +279,7 @@ export class App<State> {
const next = matched.patternMatch && !matched.methodMatch
? DEFAULT_NOT_ALLOWED_METHOD
: DEFAULT_NOT_FOUND;
: nextFn ?? DEFAULT_NOT_FOUND;
const { params, handlers, pattern } = matched;
const ctx = new FreshReqContext<State>(