@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.
19 lines (18 loc) • 1.04 kB
JavaScript
import { createMiddlewareDispatcher } from './middleware/middleware-dispatcher.js';
import { createRouteHandler } from './handler/route-handler.js';
/**
* ```ts
* import type { Middleware } from '@chubbyts/chubbyts-http-types/dist/middleware';
* import { createErrorMiddleware } from '@chubbyts/chubbyts-framework/dist/middleware/error-middleware';
* import { createRouteMatcherMiddleware } from '@chubbyts/chubbyts-framework/dist/middleware/route-matcher-middleware';
* import { createApplication } from '@chubbyts/chubbyts-framework/dist/application';
*
* const errorMiddleware: Middleware = createErrorMiddleware(...);
* const errorMiddleware: Middleware = createRouteMatcherMiddleware(...);
*
* const application = createApplication([ errorMiddleware, routeMatcherMiddleware ]);
* ```
*/
export const createApplication = (middlewares, middlewareDispatcher = createMiddlewareDispatcher(), handler = createRouteHandler(middlewareDispatcher)) => {
return (request) => middlewareDispatcher(middlewares, handler, request);
};