mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
feat: use mapToExcludeRoute() when set global prefix
This commit is contained in:
@@ -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>(
|
||||
|
||||
Reference in New Issue
Block a user