How to inject a request header in NestJS using Fastify.
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();
}
}
There is no reference for fastify middleware on nest docs: https://docs.nestjs.com/middleware
I have read fastify doc without success: https://www.fastify.io/docs/v1.13.x/Reply/ & https://www.fastify.io/docs/v1.13.x/Request/