Lex den Otter
Lex den Otter

Reputation: 161

How to set response header in nestjs with fastify

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?

Upvotes: 6

Views: 7443

Answers (2)

Jay McDoniel
Jay McDoniel

Reputation: 70412

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;
}

Upvotes: 2

Lex den Otter
Lex den Otter

Reputation: 161

The solution was:

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

Upvotes: 6

Related Questions