Skip to main content

v4.xv5.x

The v5 major version is backwards compatible with v4, unless you used it with manually-mounted ClsMiddleware to initialize the context.

The initial release of v5.x only supported NestJS 11, but backward support for NestJS 10 was added in v5.2

Compatibility with plugins remains unaffected and they only require a patch version bump to satisfy the peer dependency on nestjs-cls.

Changed default ClsMiddleware mount point

Since NestJS v11 now ships with Express v5 and Fastify v5 which changes the route matching algorithm, the default mount point of the ClsMiddleware was changed from '*' to '/' (and from (.*) to {*splat} for Fastify).

If you used the automatic middleware mounting option in ClsModule.forRoot (i.e. middleware: { mount: true }), then you don't need to do anything.

If you manually mounted the middleware, you should adjust the mount point to '/' (or any other route that is relevant to you, according to the new matching algorithm).

For Express:

export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ClsMiddleware)
- .forRoutes('*');
+ .forRoutes('/');
}
}

For Fastify

export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ClsMiddleware)
- .forRoutes('(.*)');
+ .forRoutes('{*splat}');
}
}
info

Since v5.2, nestjs-cls adds back support for NestJS v10. The correct mount point will be decided automatically by detecting the version of either Express or Fastify.