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:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user