feat(server): enable cls plugin to store request id (#9758)

POC
This commit is contained in:
fengmk2
2025-01-20 10:00:21 +00:00
parent fa5e6e1f45
commit 2ae05c28b7
7 changed files with 70 additions and 4 deletions
@@ -0,0 +1,16 @@
import { NextFunction, Request, Response } from 'express';
import { ClsServiceManager } from 'nestjs-cls';
import onHeaders from 'on-headers';
export const responseRequestIdHeader = (
_req: Request,
res: Response,
next: NextFunction
) => {
onHeaders(res, () => {
const requestId = ClsServiceManager.getClsService().getId();
res.setHeader('X-Request-Id', requestId);
});
next();
};