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?
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.
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).
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.
You can do
res.redirect('https://app.example.io');
Express docs: https://expressjs.com/en/api.html#res.redirect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With