mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
fix(core): prevent exclude method from overwriting previous calls
This commit is contained in:
@@ -45,6 +45,11 @@ class TestController {
|
||||
overviewById() {
|
||||
return RETURN_VALUE;
|
||||
}
|
||||
|
||||
@Get('multiple/exclude')
|
||||
multipleExclude() {
|
||||
return RETURN_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
@Module({
|
||||
@@ -59,6 +64,7 @@ class TestModule {
|
||||
path: 'middleware',
|
||||
method: RequestMethod.POST,
|
||||
})
|
||||
.exclude('multiple/exclude')
|
||||
.forRoutes('*');
|
||||
}
|
||||
}
|
||||
@@ -110,6 +116,12 @@ describe('Exclude middleware', () => {
|
||||
.expect(200, RETURN_VALUE);
|
||||
});
|
||||
|
||||
it(`should exclude "/multiple/exclude" endpoint`, () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/multiple/exclude')
|
||||
.expect(200, RETURN_VALUE);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
@@ -58,8 +58,9 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
|
||||
public exclude(
|
||||
...routes: Array<string | RouteInfo>
|
||||
): MiddlewareConfigProxy {
|
||||
this.excludedRoutes = this.getRoutesFlatList(routes).reduce(
|
||||
(excludedRoutes, route) => {
|
||||
this.excludedRoutes = [
|
||||
...this.excludedRoutes,
|
||||
...this.getRoutesFlatList(routes).reduce((excludedRoutes, route) => {
|
||||
for (const routePath of this.routeInfoPathExtractor.extractPathFrom(
|
||||
route,
|
||||
)) {
|
||||
@@ -70,9 +71,8 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
|
||||
}
|
||||
|
||||
return excludedRoutes;
|
||||
},
|
||||
[] as RouteInfo[],
|
||||
);
|
||||
}, [] as RouteInfo[]),
|
||||
];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user