UNPKG

edgerender

Version:
54 lines (53 loc) 1.93 kB
import { HttpError, PreResponse } from './response'; import { Sentry } from './sentry'; import { JsxChunk } from './jsx'; import { Assets, AssetConfig } from './assets'; import { PathView, Method } from './request'; import { CspRules } from './csp'; export interface RequestContext { request: Request; method: Method; url: URL; match: Record<string, string>; is_hx_request: boolean; edge_render: EdgeRender; assets: Assets; } declare type ResponseTypes = PreResponse | Response | JsxChunk | HttpError; declare type ViewReturnType = ResponseTypes | Promise<ResponseTypes>; export declare type ViewFunction = (context: RequestContext) => ViewReturnType; export interface View { allow?: Method | Method[]; view: ViewFunction; } export declare type Views = Record<string, View | ViewFunction>; declare type Page = (children: JsxChunk, context: RequestContext) => JsxChunk | Promise<JsxChunk>; export interface EdgeRenderConfig { views: Views; page?: Page; log?: boolean; show_error_details?: boolean; sentry_dsn?: string; sentry_release?: string; sentry_environment?: string; assets?: AssetConfig; security_headers?: Record<string, string>; csp?: CspRules; } export declare class EdgeRender { readonly views: PathView[]; readonly page?: Page; readonly log: boolean; readonly show_error_details: boolean; readonly sentry?: Sentry; readonly assets: Assets; readonly security_headers: Record<string, string>; constructor(config: EdgeRenderConfig); handler(event: FetchEvent): void; handle(event: FetchEvent): Promise<Response>; protected route(request: Request): Promise<PreResponse | Response>; protected on_404(context: RequestContext): Promise<Response>; protected on_http_error(request: Request, exc: HttpError): Promise<Response>; protected prepare_response(r: PreResponse): Response; } export {};