UNPKG

@chubbyts/chubbyts-framework

Version:

A minimal, highly performant middleware PSR-15 inspired function based micro framework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

20 lines (19 loc) 759 B
import { pipe } from '@chubbyts/chubbyts-undici-server/dist/server'; import { isRoute } from '../router/route.js'; /** * ```ts * import type { Handler } from '@chubbyts/chubbyts-undici-server/dist/server'; * import { createRouteHandler } from '@chubbyts/chubbyts-framework/dist/handler/route-handler'; * * const routeHandler: Handler = createRouteHandler(); * ``` */ export const createRouteHandler = () => { return (request) => { const route = request.attributes.route; if (isRoute(route)) { return pipe(route.middlewares)(request, route.handler); } throw new Error(`Request attribute "route" missing or wrong type "${typeof route}", please add the "${createRouteHandler.name}" middleware.`); }; };