0

I currently have a react native webview where the url is set to the path to a html file inside my workspace. In development, everything is working accordingly and the page gets rendered with the parameters set in the url.

My problem, i would like to move to production and hence the IP address used in the path to the index.html file is no longer available.

Here is my code:

const [url,setUrl]=useState(`http://IPADDRESS_ONMYCOMPUTER:19000/app/screens/Payment/index.html?sessionId=${route.params.sessionId}`)


return (
source={{uri:url}}
)

Update

I have created the html files on my server and are working accordingly when i access them from the browser. Unfortunately, they are not working inside my webview in react native.

I keep getting an error and the page doesnt load.

Here is my updated Code:

Here is my code:

const [url,setUrl]=useState(`http://SERVERIPADDRESS/api/payments/index.html?sessionId=${route.params.sessionId}`)


return (
source={{uri:url}}
)

kd12345
  • 689
  • 10
  • 29

1 Answers1

0

for this you do not need to your local url. there are multiple solution to this. if you page is static you can copy the source code and use this package to render your html. if the page is dynamic you have to put that on some server and the specify that's url.

if your url is http so have to allow http request in your application.

for android add this

<application android:usesCleartextTraffic="true">
</application>

for details visit this question

for iOS visit this

Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
  • Yes its dynamic, i already have my nodejs backend on an ubuntu server. Should i access the server and create a new html file inside and make a get request to that file? – kd12345 Jan 11 '23 at 06:56
  • yes. you have to put that on the server and get it through the GET request. or just make it public to access that file. – Engr.Aftab Ufaq Jan 11 '23 at 08:29
  • Thats what i did, but now the url doesnt open inside the webview and opens when i use it in a browser. Why is that? – kd12345 Jan 11 '23 at 08:31
  • Hi, i had a webview rendering a html file using this path `http://LocalIPAddress/app/index.html?sessionId=${route.params.sessionId}` everything was working accordingly in development phase. To move to production, i had to add the index.html file to my backend. `http://SERVERIPADDRESS/api/html/index.html?sessionId=${route.params.sessionId}`. Now the url does not open inside the webview. Why is that? – kd12345 Jan 11 '23 at 08:31
  • http does not work. make it https – Engr.Aftab Ufaq Jan 11 '23 at 08:34
  • it was working when i was using my local ip address – kd12345 Jan 11 '23 at 08:54
  • in local it work. to make it work you have to config it for android and iOS. i am updating my answer to add these/ – Engr.Aftab Ufaq Jan 11 '23 at 09:09
  • Hi, the thing is i am using expo SDK so the solution provided will no tbe possible – kd12345 Jan 11 '23 at 09:22
  • for this please use these in app.json or simple remove http form the link and add https. and it will work. – Engr.Aftab Ufaq Jan 11 '23 at 09:34
  • How exactly should they be placed? also, doing so i dont need to register the IP address to get an SSL certificate? – kd12345 Jan 11 '23 at 09:38
  • https://SERVERIPADDRESS/api/html/index.html?sessionId=${route.params.sessionId} use this address – Engr.Aftab Ufaq Jan 11 '23 at 09:53
  • without http and https i keep getting the same error url was not found – kd12345 Jan 11 '23 at 09:55
  • please paste your original url. here – Engr.Aftab Ufaq Jan 11 '23 at 10:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/251029/discussion-between-engr-aftab-ufaq-and-kd12345). – Engr.Aftab Ufaq Jan 11 '23 at 10:53