BREAKING: merge API routes and pages concept (#53)

This commit merges API routes and pages into a single concept. The
pages/api folder is now not special anymore.
This commit is contained in:
Luca Casonato
2021-09-25 10:49:53 +02:00
committed by GitHub
parent aeaddb1eaa
commit f5b3faf0d8
12 changed files with 150 additions and 121 deletions
+18 -13
View File
@@ -4,29 +4,34 @@ import { PageConfig, PageProps } from "../runtime/types.ts";
import { RenderContext, RenderFn } from "./render.tsx";
export interface PageModule {
default: ComponentType<PageProps>;
default?: ComponentType<PageProps>;
handler?: Handler | Handlers;
config?: PageConfig;
}
export interface HandlerContext<
T extends Record<string, string> = Record<string, string>,
> {
req: Request;
match: router.MatchResult<T>;
render?: () => Promise<Response>;
}
export type Handler = (ctx: HandlerContext) => Response | Promise<Response>;
export type Handlers = {
[K in typeof router.METHODS[number]]?: Handler;
};
export interface Page {
route: string;
url: string;
name: string;
component: ComponentType<PageProps>;
component?: ComponentType<PageProps>;
handler: Handler | Handlers;
runtimeJS: boolean;
}
export type ApiRouteModule = {
[K in "default" | typeof router.METHODS[number]]?: router.MatchHandler;
};
export interface ApiRoute {
route: string;
url: string;
name: string;
handlers: Record<string, router.MatchHandler>;
}
export interface RendererModule {
render(ctx: RenderContext, render: RenderFn): void;
postRender(ctx: RenderContext, bodyHtml: string): void;