Skip to content

question: middlewares are not scoped to routePrefix when using multiple routes #555

Closed
@abourdin

Description

@abourdin

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

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions