Files
Public/apps/api/src/common/middleware/request-id.middleware.ts
T
daiyongkang 76f266645d Initial commit: 风影 OA 全栈源码(API/Web/Flutter/IM)
含 Phase 1.1 IM seq 排序、断线重连、多端已读同步与微信式语音转文字 UI。
排除 node_modules、构建产物、安装包与 .env 密钥。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 10:04:03 +00:00

16 lines
516 B
TypeScript

import { randomUUID } from 'crypto';
import { Injectable, NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';
export const REQUEST_ID_HEADER = 'x-request-id';
@Injectable()
export class RequestIdMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: NextFunction) {
const id = (req.headers[REQUEST_ID_HEADER] as string) || randomUUID();
req.headers[REQUEST_ID_HEADER] = id;
res.setHeader(REQUEST_ID_HEADER, id);
next();
}
}