UNPKG

@respond-run/router

Version:

Filesystem-based router for Vite-powered Cloudflare Workers

18 lines (17 loc) 859 B
export type Handler<TEnv = unknown, TCtx = DefaultExecutionContext> = (request: Request & { params: Record<string, string>; }, env: TEnv, ctx: TCtx) => 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;