Skip to content

Commit 4485f97

Browse files
committed
Fix direct loaded middlewares order of registering
1 parent ed63979 commit 4485f97

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/RoutingControllers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export class RoutingControllers {
9595
this.metadataBuilder
9696
.buildMiddlewareMetadata(classes)
9797
.filter(middleware => middleware.global && middleware.type === type)
98-
.sort((middleware1, middleware2) => middleware1.priority - middleware2.priority)
99-
.reverse()
98+
.sort((middleware1, middleware2) => middleware2.priority - middleware1.priority)
10099
.forEach(middleware => this.driver.registerMiddleware(middleware));
101100

102101
return this;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export function createExecutor(driver: Driver, options: RoutingControllersOption
215215
new RoutingControllers(driver, options)
216216
.initialize()
217217
.registerInterceptors(interceptorClasses)
218-
.registerMiddlewares("before")
218+
.registerMiddlewares("before", middlewareClasses)
219219
.registerControllers(controllerClasses)
220220
.registerMiddlewares("after", middlewareClasses); // todo: register only for loaded controllers?
221221
}

src/metadata-builder/MetadataArgsStorage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export class MetadataArgsStorage {
6464
* Filters registered middlewares by a given classes.
6565
*/
6666
filterMiddlewareMetadatasForClasses(classes: Function[]): MiddlewareMetadataArgs[] {
67-
return this.middlewares.filter(ctrl => {
68-
return classes.filter(cls => ctrl.target === cls).length > 0;
69-
});
67+
return classes
68+
.map(cls => this.middlewares.find(mid => mid.target === cls))
69+
.filter(midd => midd !== undefined); // this might be not needed if all classes where decorated with `@Middleware`
7070
}
7171

7272
/**

0 commit comments

Comments
 (0)