1

i have a react native frontend and a nodejs backend. In one of my API calls i am getting a redirectHTML from a gateway to display to the users. The redirectHTML obtained is used in react native Webview to get displayed. my problem is the only way to know that the transaction is success or not is from the url. I have tried res.redirect and res.writeHead and both change the content of the screen but the URL still remains the same.

Server side

router.get(
  "/pay/authenticate/result",
  async(req, res) => {

    console.log(req.query)

// res.redirect(302,"/");

res.writeHead(302,{'Location':'https://www.google.com/'});
res.end("");
    
});

client Side


<WebView
style={{flex:1}} 
source={{html:`${authenticateWebViewUrl}`}} //this is the redirectHTML that came from the response
onNavigationStateChange={(navState) => {
  console.log(navState)
}}
scalesPageToFit={false}
javaScriptEnabled={true}
/>

kd12345
  • 689
  • 10
  • 29

1 Answers1

0

res.redirect with 302 will add the temporary redirection, if you want a permanent redirection, prefer HTTP 301. Reference

res.writeHead + res.end does not, on its own, cause the redirection to a new URL.

Edit: Typo req and res.

Jishan Shaikh
  • 1,572
  • 2
  • 13
  • 31
  • Hi, thank you for getting back to me. I am currently implementing with a Payment Gateway. When the user pressess pay on the gateway an API call is made to my nodeJS endpoint, so the only thing possible for me to do is change the URL once payment is complete and listen to that change inside my Webview and continue the flow from there. ```Isnt it supposed to be res.redirect not req.redirect?``` – kd12345 Dec 13 '22 at 07:11
  • Yes, it was res, corrected, Thanks. The main point was 301/302 though. – Jishan Shaikh Dec 13 '22 at 07:53
  • I gave that a try and still, the url is not changing. is this because everything is done inside an index.html file? – kd12345 Dec 13 '22 at 08:10