5

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?

Lex den Otter
  • 133
  • 1
  • 7

2 Answers2

5

The solution was:

res.header('key', 'value');
Lex den Otter
  • 133
  • 1
  • 7
1

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;
}
Jay McDoniel
  • 57,339
  • 7
  • 135
  • 147