如何使用 Fastify 在 NestJS 中注入请求头。
import { FastifyRequest, FastifyReply } from 'fastify'; // fastify types are not valid
@Injectable()
export class TracingMiddleware implements NestMiddleware {
use(req: any, res: any, next: () => void) {
console.log('MyRequestHeaderKey', req.headers['MyRequestHeaderKey']); // find out how to get a header
res.header('MyResponseHeaderKey', 'MyResponseHeaderValue'); // find out how to set headers
next();
}
}
嵌套文档中没有关于 fastify 中间件的参考:https ://docs.nestjs.com/middleware
我已经阅读了 fastify 文档但没有成功:https ://www.fastify.io/docs/v1.13.x/Reply/ & https://www.fastify.io/docs/v1.13.x/Request/