Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): prevent exclude method from overwriting previous calls #13614

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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