@chubbyts/chubbyts-framework
Version:
A minimal, highly performant middleware PSR-15 inspired function based microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.
18 lines (17 loc) • 688 B
JavaScript
/**
* ```ts
* import type { Middleware } from '@chubbyts/chubbyts-http-types/dist/middleware';
* import type { Match } from '@chubbyts/chubbyts-framework/dist/router/route-matcher';
* import { createRouteMatcherMiddleware } from '@chubbyts/chubbyts-framework/dist/middleware/route-matcher-middleware';
*
* const match: Match = ...;
*
* const routeMatcherMiddleware: Middleware = createRouteMatcherMiddleware(match);
* ```
*/
export const createRouteMatcherMiddleware = (match) => {
return async (request, handler) => {
const route = match(request);
return handler({ ...request, attributes: { ...request.attributes, route, ...route.attributes } });
};
};