feat: als and prisma
This commit is contained in:
19
core/als/request-context.middleware.ts
Normal file
19
core/als/request-context.middleware.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Injectable, NestMiddleware } from '@nestjs/common';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { RequestContextService } from './request-context.service';
|
||||
|
||||
@Injectable()
|
||||
export class RequestContextMiddleware implements NestMiddleware {
|
||||
constructor(private readonly ctx: RequestContextService) {}
|
||||
|
||||
use(req: Request, _: Response, next: NextFunction) {
|
||||
const context = {
|
||||
requestId: randomUUID(),
|
||||
correlationId: (req.headers['x-correlation-id'] as string) ?? undefined,
|
||||
headers: req.headers as Record<string, string>,
|
||||
};
|
||||
|
||||
this.ctx.run(context, next);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user