Skip to main content
Module

x/fresh/src/server/defines.ts

The next-gen web framework.
Extremely Popular
Go to Latest
File
import { ComponentChildren } from "preact";import { AsyncLayout, AsyncRoute, FreshConfig, RouteContext } from "./types.ts";import { checkAsyncComponent } from "./render.ts";
export function defineConfig(config: FreshConfig): FreshConfig { return config;}
// Route creation helpersexport function defineRoute< T,>( fn: ( req: Request, ctx: RouteContext<void, T>, ) => ComponentChildren | Response | Promise<ComponentChildren | Response>,): AsyncRoute<void, T> { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx);}
// Layout creation helperexport function defineLayout<T>( fn: ( req: Request, ctx: RouteContext<void, T>, ) => ComponentChildren | Response | Promise<ComponentChildren | Response>,): AsyncLayout<void, T> { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx);}
// App creation helperexport function defineApp<T>( fn: ( req: Request, ctx: RouteContext<void, T>, ) => ComponentChildren | Response | Promise<ComponentChildren | Response>,): AsyncLayout<void, T> { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx);}