Using fastify
library I want to be redirected to a web-page.
Looking at all the examples in docs, it seems like it covers only route-to-route redirection.
Link to redirect docs
fastify.post('/v1/launch', async (req, res) => {
response.redirect('/empty-cart');
});
The code above results in 404 error trying to find that route.
But how it can be redirected to external page? Thanks!
Update:
Trying to redirect to
with ERR_NAME_NOT_RESOLVED
error
Using fastify
library I want to be redirected to a web-page.
Looking at all the examples in docs, it seems like it covers only route-to-route redirection.
Link to redirect docs
fastify.post('/v1/launch', async (req, res) => {
response.redirect('/empty-cart');
});
The code above results in 404 error trying to find that route.
But how it can be redirected to external page? Thanks!
Update:
Trying to redirect to https://my-domain./empty-cart
with ERR_NAME_NOT_RESOLVED
error
-
response.redirect('https://example.');
– 0stone0 Commented Aug 9, 2021 at 12:11 - 1 @0stone0 question is updated. still not working – poltorin Commented Aug 9, 2021 at 12:23
- If you enter my-domain./empty-cart in your browser do you get anything or a 404? – Frazer Commented Aug 9, 2021 at 13:18
- @Frazer look update above – poltorin Commented Aug 9, 2021 at 13:20
- I mean if you go to https : //my-domain./empty-cart directly, not via a redirection. – Frazer Commented Aug 9, 2021 at 13:29
2 Answers
Reset to default 1Please try
response.redirect('https://stackoverflow./')
Docs: https://www.fastify.io/docs/latest/Reference/Reply/#redirectcode--dest
In nest js i have tried this way with statuscode of redirection(301) and it worked for me without statucode 301 it was not redirect as there is some open ticket on fastify-nestjs.
@Post('success')
async payment_success_handler(@Req() req , @Res() res , @Body() body ) {
console.log(req.headers);
console.log("FormData log" , req.body)
console.log("@Body" , body)
return res.redirect(301 ,'http://example./success');
}