How to set response header in nestjs with fastify

Viewed 3250

I'm trying to set a custom reponse header in a nest js controller and using fastify.
Currently I'm trying to do:

@Post()
async methodName(@Res res){
res.set('key', 'value');
};

But I get the error: res.set is not a function
Can someone help me?

2 Answers

The solution was:

res.header('key', 'value');

If you are needing to set a static header value as well, you can always use the @Header() decorator on the route handler so you could have

@Post()
@Header('key', 'value')
async method() {
  return something;
}
Related