Skip to content

middlewares are not scoped to routePrefix when using multiple routes #927

Closed
@dksdheeraj

Description

@dksdheeraj

Any solution of below question. Duplidate issue of #555

#555

Let's assume an application is defined as following, instantiating several routes that need different middlewares (one for the application endpoints, the other for the admin endpoints):

useExpressServer(application, {
routePrefix: '/app',
controllers: [__dirname + '/app/controllers/**/*.ts'],
middlewares: [AppMiddleware1, AppMiddleware2]
});

useExpressServer(application, {
routePrefix: '/admin',
controllers: [__dirname + '/admin/controllers/**/*.ts'],
middlewares: [AdminMiddleware1]
});
When doing so, the middlewares are executed globally and not scoped to the controllers attached to the route. If another route is defined, here is what happens:

when calling an url under /app: AppMiddleware1, AppMiddleware2 are executed
when calling an url under /admin: AppMiddleware1, AppMiddleware2 and AdminMiddleware1 are executed
Controllers being correctly attached to a given route, I think middlewares should be doing the same, but from my recent discoveries, it seems this is not properly supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: has PRIssues which has a related PR closing the issue.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions