forked from wangziqi/gongxue-base
feat: migrate backend foundation to NestJS
This commit is contained in:
14
apps/api/src/nest/api.interceptor.ts
Normal file
14
apps/api/src/nest/api.interceptor.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { FastifyReply } from 'fastify';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { withResponseMeta } from '../core/http.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApiEnvelopeInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||||
const reply = context.switchToHttp().getResponse<FastifyReply>();
|
||||
return next.handle().pipe(map(body => withResponseMeta(body, String(reply.getHeader('x-request-id') || ''))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user