Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MiddlewareBuilder

Hierarchy

  • MiddlewareBuilder

Implements

  • any

Index

Constructors

constructor

Properties

Private middlewareCollection

middlewareCollection: any = new Set<MiddlewareConfiguration>()

Private routesMapper

routesMapper: RoutesMapper

Static Private ConfigProxy

ConfigProxy: (Anonymous class) = class implements MiddlewareConfigProxy {private excludedRoutes: RouteInfo[] = [];constructor(private readonly builder: MiddlewareBuilder,private readonly middleware: Array<Type<any> | Function | any>,) {}public getExcludedRoutes(): RouteInfo[] {return this.excludedRoutes;}public exclude(...routes: Array<string | RouteInfo>): MiddlewareConfigProxy {const { routesMapper } = this.builder;this.excludedRoutes = this.mapRoutesToFlatList(routes.map(route => routesMapper.mapRouteToRouteInfo(route)),);return this;}public forRoutes(...routes: Array<string | Type<any> | RouteInfo>): MiddlewareConsumer {const { middlewareCollection, routesMapper } = this.builder;const forRoutes = this.mapRoutesToFlatList(routes.map(route => routesMapper.mapRouteToRouteInfo(route)),);const configuration = {middleware: filterMiddleware(this.middleware),forRoutes: forRoutes.filter(route => !this.isRouteExcluded(route)),};middlewareCollection.add(configuration);return this.builder;}private mapRoutesToFlatList(forRoutes: RouteInfo[][]): RouteInfo[] {return forRoutes.reduce((a, b) => a.concat(b));}private isRouteExcluded(routeInfo: RouteInfo): boolean {const pathLastIndex = routeInfo.path.length - 1;const validatedRoutePath =routeInfo.path[pathLastIndex] === '/'? routeInfo.path.slice(0, pathLastIndex): routeInfo.path;return this.excludedRoutes.some(excluded => {const isPathEqual = validatedRoutePath === excluded.path;if (!isPathEqual) {return false;}return (routeInfo.method === excluded.method ||excluded.method === RequestMethod.ALL);});}}

Methods

apply

build

Generated using TypeDoc