poltorin
poltorin

Reputation: 302

Fastify redirect to external URL

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.

result

But how it can be redirected to external page? Thanks!

Update: Trying to redirect to https://my-domain.com/empty-cart

result2

with ERR_NAME_NOT_RESOLVED error

Upvotes: 4

Views: 11447

Answers (2)

Arpit Nakrani
Arpit Nakrani

Reputation: 1

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.com/success');

  }

Upvotes: 0

Eanthmue
Eanthmue

Reputation: 477

Please try

response.redirect('https://stackoverflow.com/')

Docs: https://www.fastify.io/docs/latest/Reference/Reply/#redirectcode--dest

Upvotes: 1

Related Questions