routing-controllers
routing-controllers copied to clipboard
Set HttpCode other than default 302 on @Redirect
Is it possible to set a different status code other than 302 when using the @Redirect
decorator? Neither @HttpCode
nor response.status(301)
seem to work.
I ended up not using a decorator for redirection, but grabbing response
using @Res
, and then calling redirect
on that:
response.redirect(303, 'https://example.com');
return response;
If I use
response.redirect(301, "https://example.com");
then, any async interceptor doesn't seem to work correctly.
It would be better idea to add support to set status code to @Redirect
decorator.
Similar problem here. I am generating an AWS pre-signed url. Passing it with @Redirect(':url')
does not work, as the redirect seems to encode the query parameters.
Using return response.redirect(url)
works on the client side, but on the server it activates the 404 middleware and Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
.
Anything that I can do about this? Thanks in advance!
Hi @sheinzle That's a common issue happens when you controller returns undefined and you error handler return by default an 404 error, you can add the next lines of code on you error handler
if (res.headersSent) {
return;
}
Hope this help.