nestjs-configure-after
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    nestjs-configure-after

    npm GitHub branch checks state Supported platforms: Express & Fastify

    Snyk Vulnerabilities for npm package Dependencies status Dependabot Maintainability

    Using NestJS?

    Have middlewares that are set in configure(consuer: MiddlewareConsumer) {} of it's module?

    Do you want to control the order of execution of these middlewares?

    Install

    npm i nestjs-configure-after

    Example

    Let's assume we have ModuleA, ModuleB and ModuleC, and each has own middleares setup. And we want these middleware to be set in the right order, like A -> B -> C. By default NestJS does not provide the way to set the order. But with this module it's you can:

    import { After } from 'nestjs-configure-after'
    
    @Module({})
    //
    // Empty if independent
    //
    @After()
    class ModuleA {
      configure(consumer: MiddlewareConsumer) {
        consumer
          .apply(FirstMiddleware)
          .forRoutes('*');
      }
    }
    
    @Module({})
    //
    // Pass module that should configure it's middlewares
    // before the current one
    //
    @After(ModuleA)
    class ModuleB {
      configure(consumer: MiddlewareConsumer) {
        consumer
          .apply(SecondMiddlewareThatShouldBeExecutedAfterTheFirstOne)
          .forRoutes('*');
      }
    }
    
    @Module({})
    //
    // ...Or even pass several modules
    //
    @After(ModuleA, ModuleB)
    class ModuleC {
      configure(consumer: MiddlewareConsumer) {
        consumer
          .apply(TheLastMiddleware)
          .forRoutes('*');
      }
    }
    
    @Module({
      // And for now it does not matter in which
      // order modules are set in `imports` field
      // Middlewares will be setup in the right order.
      imports: [ModuleC, ModuleA, ModuleB, ...],
      controllers: [...]
    })
    class App {}

    Do you use this library?
    Don't be shy to give it a star! ★

    Also if you are into NestJS ecosystem you may be interested in one of my other libs:

    nestjs-pino

    GitHub stars npm

    Platform agnostic logger for NestJS based on pino with request context in every log


    nestjs-session

    GitHub stars npm

    Idiomatic session module for NestJS. Built on top of express-session


    nestjs-cookie-session

    GitHub stars npm

    Idiomatic cookie session module for NestJS. Built on top of cookie-session


    nestjs-roles

    GitHub stars npm

    Type safe roles guard and decorator made easy


    nestjs-injectable

    GitHub stars npm

    @Injectable() on steroids that simplifies work with inversion of control in your hexagonal architecture


    nest-ratelimiter

    GitHub stars npm

    Distributed consistent flexible NestJS rate limiter based on Redis


    create-nestjs-middleware-module

    GitHub stars npm

    Create simple idiomatic NestJS module based on Express/Fastify middleware in just a few lines of code with routing out of the box


    nestjs-configure-after

    GitHub stars npm

    Declarative configuration of NestJS middleware order

    Install

    npm i nestjs-configure-after

    DownloadsWeekly Downloads

    600

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    12.2 kB

    Total Files

    5

    Last publish

    Collaborators

    • iamolegga