/** * @jorvel/ssr — server-route convention. * * A tiny, dependency-free API router (method + path → `Request → Response`) * that any adapter can consult BEFORE falling through to SSR. This is the * seam tRPC / Hono / a hand-written handler plug into: mount their fetch * handler as a catch-all route, or use the built-in matcher for simple JSON * endpoints. * * Edge-safe: Web `Request`/`Response`, `:param` + `*` splat matching, no Node * builtins. */ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; export interface RouteContext { request: Request; url: URL; params: Record; } export type RouteHandler = (ctx: RouteContext) => Response | Promise; export interface RouteDef { method: HttpMethod | '*'; path: string; handler: RouteHandler; } export declare function defineRoute(method: RouteDef['method'], path: string, handler: RouteHandler): RouteDef; export interface ApiRouter { /** Handle a request. Returns a Response, or `null` when no route matched. */ handle(request: Request): Promise; routes: RouteDef[]; } export interface CreateApiRouterOptions { /** Prefix every route path is mounted under, e.g. `/api`. Default `''`. */ prefix?: string; /** Mount a foreign fetch handler (tRPC/Hono) as the fallback for the prefix. */ fallback?: RouteHandler; } /** * Build a router from route defs. First method+path match wins; `'*'` method * matches any verb. Returns `null` on no match so the caller can fall through * to SSR page rendering. */ export declare function createApiRouter(routes: RouteDef[], opts?: CreateApiRouterOptions): ApiRouter; export declare function json(data: unknown, init?: ResponseInit): Response; export declare function notFound(message?: string): Response; //# sourceMappingURL=server-routes.d.ts.map