feat: support lazily loading routes/handlers (#3131)

We can improve cold start times by only loading route modules when the particular pattern matches. This PR introduces the concept of lazy middlewares, routes and handlers to do that.
This commit is contained in:
Marvin Hagemeister
2025-07-25 14:33:28 +02:00
committed by GitHub
parent 097fb6b27c
commit 3ad3e6ecf3
24 changed files with 529 additions and 133 deletions
+5
View File
@@ -1,4 +1,5 @@
import * as path from "@std/path";
import type { Lazy, MaybeLazy } from "./types.ts";
export function assertInDir(
filePath: string,
@@ -68,3 +69,7 @@ const PATH_TO_SPEC = /[\\/]+/g;
export function pathToSpec(str: string): string {
return str.replaceAll(PATH_TO_SPEC, "/");
}
export function isLazy<T>(value: MaybeLazy<T>): value is Lazy<T> {
return typeof value === "function";
}