Workaround for getting Request information from a non request-scoped service in NestJs. Initially taken from this gist, and then changed to use AsyncLocalStorage
Full example in test
folder
@Module({
imports: [RequestContextModule], // automatically binds the proper middleware
providers: [...],
controllers: [..],
})
export class AppModule {}
Accessing request from service
@Injectable()
export class SingletonService {
getRequestId() {
const req: Request = RequestContext.currentContext.req;
return req.requestId;
}
}
Updated peer dependencies to 8.x
Use async_hooks
instead asyncctx
as it's deprecated
Updated NestJs peer dependencies to 9.x
- Removed express from peer dependencies
- Added minimal generic support
Updated NestJs peer dependencies to 10.x