Skip to content

Commit 4d88c79

Browse files
fix(core): prevent exclude method from overwriting previous calls
1 parent aa7538f commit 4d88c79

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

integration/hello-world/e2e/exclude-middleware.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class TestController {
4545
overviewById() {
4646
return RETURN_VALUE;
4747
}
48+
49+
@Get('multiple/exclude')
50+
multipleExclude() {
51+
return RETURN_VALUE;
52+
}
4853
}
4954

5055
@Module({
@@ -59,6 +64,7 @@ class TestModule {
5964
path: 'middleware',
6065
method: RequestMethod.POST,
6166
})
67+
.exclude('multiple/exclude')
6268
.forRoutes('*');
6369
}
6470
}
@@ -110,6 +116,12 @@ describe('Exclude middleware', () => {
110116
.expect(200, RETURN_VALUE);
111117
});
112118

119+
it(`should exclude "/multiple/exclude" endpoint`, () => {
120+
return request(app.getHttpServer())
121+
.get('/multiple/exclude')
122+
.expect(200, RETURN_VALUE);
123+
});
124+
113125
afterEach(async () => {
114126
await app.close();
115127
});

packages/core/middleware/builder.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
5858
public exclude(
5959
...routes: Array<string | RouteInfo>
6060
): MiddlewareConfigProxy {
61-
this.excludedRoutes = this.getRoutesFlatList(routes).reduce(
62-
(excludedRoutes, route) => {
61+
this.excludedRoutes = [
62+
...this.excludedRoutes,
63+
...this.getRoutesFlatList(routes).reduce((excludedRoutes, route) => {
6364
for (const routePath of this.routeInfoPathExtractor.extractPathFrom(
6465
route,
6566
)) {
@@ -70,9 +71,8 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
7071
}
7172

7273
return excludedRoutes;
73-
},
74-
[] as RouteInfo[],
75-
);
74+
}, [] as RouteInfo[]),
75+
];
7676

7777
return this;
7878
}

0 commit comments

Comments
 (0)