Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In express how do I redirect a user to an external url?

I have a payment system using node.js and braintree, when the payment is successful I want to send the user to the back end. My back end is setup elsewhere.

I have tried

res.writeHead(301,   {Location: 'http://app.example.io'} ); res.end(); 

So window.location is obviously not available. I cant think of any ways to redirect a user?

like image 914
Michael Joseph Aubry Avatar asked Feb 05 '15 19:02

Michael Joseph Aubry


People also ask

How do I redirect a URL to another URL Express?

The res. redirect() function lets you redirect the user to a different URL by sending an HTTP response with status 302. The HTTP client (browser, Axios, etc.) will then "follow" the redirect and send an HTTP request to the new URL as shown below.

What is external redirect?

URL redirection is forwarding a user from one page to another page. There are basically two types of redirection:- Internal Redirection: Forwarding to internal pages. External Redirection: Forwarding to external pages (Other domains).

How get full URL in Express?

To get the full URL in Express and Node. js, we can use the url package. to define the fullUrl function that takes the Express request req object. And then we call url.


1 Answers

You can do

res.redirect('https://app.example.io'); 

Express docs: https://expressjs.com/en/api.html#res.redirect

like image 161
TheIronDeveloper Avatar answered Sep 25 '22 17:09

TheIronDeveloper