Skip to content

Commit

Permalink
fix(core): prevent exclude method from overwriting previous calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dragontaek-lee committed May 25, 2024
1 parent aa7538f commit 4d88c79
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 4d88c79

Please sign in to comment.