3.0.0 • Published 9 months ago

nestjs-configure-after v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 months ago

Using NestJS?

Do you have middlewares set via configure(consuer: MiddlewareConsumer) {} and 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 its own middleware setup. And we want these middlewares to be set in the correct order, like A -> B -> C. By default NestJS does not provide the way to set the order. But with this library it's possible:

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 {}
2.0.0-alpha.94f833

9 months ago

2.0.0-alpha.e78aea

12 months ago

2.0.0-alpha.aac712

9 months ago

2.0.0-alpha.18123

10 months ago

2.0.0-alpha.80be9c

10 months ago

3.0.0

9 months ago

2.0.0-alpha.ae58d9

9 months ago

2.0.0-alpha.426920

10 months ago

2.0.0-alpha.37f847

12 months ago

2.0.0-alpha.aff957

10 months ago

2.0.0-alpha.7e5940

10 months ago

2.0.0-alpha.39370

11 months ago

2.0.0-alpha.feb130

9 months ago

2.0.0-alpha.d7f3e0

9 months ago

2.0.0-alpha.18588b

10 months ago

2.0.0-alpha.4c3588

9 months ago

2.0.0-alpha.e7a3ad

12 months ago

2.0.0-alpha.fb6bca

11 months ago

2.0.0-alpha.3c8044

10 months ago

2.0.0-alpha.65b5c9

12 months ago

2.0.0-alpha.2d3dcb

9 months ago

2.0.0-alpha.6c08f5

12 months ago

2.0.0-alpha.d88f64

12 months ago

2.0.0-alpha.d450e4

10 months ago

2.0.0-alpha.cd95fc

12 months ago

2.0.0-alpha.6a094e

9 months ago

2.0.0-alpha.0bb838

12 months ago

2.0.0-alpha.3a8fa8

9 months ago

2.0.0-alpha.3a3dda

9 months ago

2.0.0-alpha.1d506c

9 months ago

2.0.0-alpha.dfa6b2

11 months ago

2.0.0-alpha.61397b

12 months ago

2.0.0-alpha.007bbf

11 months ago

2.0.0-alpha.93238

10 months ago

2.0.0-alpha.84e538

12 months ago

2.0.0-alpha.f1fb1c

12 months ago

2.0.0-alpha.8111

2 years ago

2.0.0

3 years ago

1.0.3

4 years ago

1.0.1

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago