@respond-run/router
Version:
Filesystem-based router for Vite-powered Cloudflare Workers
16 lines (15 loc) • 849 B
TypeScript
export type Handler<TEnv = unknown, TCtx = DefaultExecutionContext> = (request: Request, env: TEnv, ctx: TCtx, params: Record<string, string>) => Promise<Response>;
export type RouteModule<TEnv = unknown, TCtx = DefaultExecutionContext> = {
[method: string]: Handler<TEnv, TCtx> | undefined;
};
export interface DefaultExecutionContext {
waitUntil(promise: Promise<any>): void;
}
/**
* Creates a route handler from a Vite import.meta.glob() result
*/
export declare function createRouter<TEnv = unknown, TCtx = DefaultExecutionContext>(globs: Record<string, () => Promise<unknown>>): (request: Request, env: TEnv, ctx: TCtx) => Promise<Response>;
/**
* Optional helper for defining routes with strong type hints.
*/
export declare function defineRoute<TEnv = unknown, TCtx = DefaultExecutionContext>(fn: Handler<TEnv, TCtx>): typeof fn;