feat: use mapToExcludeRoute() when set global prefix

This commit is contained in:
codytseng
2022-11-23 22:34:25 +08:00
parent 7d1fa9a216
commit 60772c39e1
5 changed files with 54 additions and 47 deletions

View File

@@ -1,6 +1,10 @@
import { RequestMethod } from '@nestjs/common';
import { HttpServer, RouteInfo, Type } from '@nestjs/common/interfaces';
import { isFunction } from '@nestjs/common/utils/shared.utils';
import {
addLeadingSlash,
isFunction,
isString,
} from '@nestjs/common/utils/shared.utils';
import { iterate } from 'iterare';
import * as pathToRegexp from 'path-to-regexp';
import { v4 as uuid } from 'uuid';
@@ -8,13 +12,22 @@ import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadat
import { isRouteExcluded } from '../router/utils';
export const mapToExcludeRoute = (
routes: RouteInfo[],
routes: (string | RouteInfo)[],
): ExcludeRouteMetadata[] => {
return routes.map(({ path, method }) => ({
path,
pathRegex: pathToRegexp(path),
requestMethod: method,
}));
return routes.map(route => {
if (isString(route)) {
return {
path: route,
requestMethod: RequestMethod.ALL,
pathRegex: pathToRegexp(addLeadingSlash(route)),
};
}
return {
path: route.path,
requestMethod: route.method,
pathRegex: pathToRegexp(addLeadingSlash(route.path)),
};
});
};
export const filterMiddleware = <T extends Function | Type<any> = any>(