Skip to content

Commit

Permalink
Merge pull request #13614 from dragontaek-lee/fix/middleware-builder-…
Browse files Browse the repository at this point in the history
…exclude-overwrite

fix(core): prevent exclude method from overwriting previous calls
  • Loading branch information
kamilmysliwiec authored Jun 3, 2024
2 parents 2d5a7b8 + 4d88c79 commit de86355
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions integration/hello-world/e2e/exclude-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class TestController {
overviewById() {
return RETURN_VALUE;
}

@Get('multiple/exclude')
multipleExclude() {
return RETURN_VALUE;
}
}

@Module({
Expand All @@ -59,6 +64,7 @@ class TestModule {
path: 'middleware',
method: RequestMethod.POST,
})
.exclude('multiple/exclude')
.forRoutes('*');
}
}
Expand Down Expand Up @@ -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();
});
Expand Down
10 changes: 5 additions & 5 deletions packages/core/middleware/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)) {
Expand All @@ -70,9 +71,8 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
}

return excludedRoutes;
},
[] as RouteInfo[],
);
}, [] as RouteInfo[]),
];

return this;
}
Expand Down

0 comments on commit de86355

Please sign in to comment.