How to get fetch TOWARDS localhost to FUNCTION on CARDOVA Android #536
Replies: 1 comment
-
This domain will be the local device itself, so unless if your android emulator/device is running a web server on port 3000, this won't work. I'm going to assume that you're not running the web server on the android device, that web server running port 3000 is running on your own workstation. With that assumption... there are two options, one is only valid for android emulators. The other will work on both emulators and physical devices, for as long as they are connected to the same network (connected to the same wifi/router). Emulator Only solutionThe android emulators has a special network interface that refers to the host machine. IP So: const response = await fetch('http://10.0.2.2:3000/poc3/convert', {
method: 'POST',
body: formData,
headers: { 'Accept': 'audio/mpeg' },
}); Should work inside android emulators, assuming that you have a webserver running on your workstation on port 3000. Private network solutionPrivate home networks typically allows unfettered access to other devices on the network, so you can use your workstation private ip to connect to the server, you just need to know how to find the your private ip. Each router is different but most routers by default operate on On linux/mac you can use: wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 On windows the equivalent command is Ethernet adapter Ethernet: Connection-specific DNS Suffix . : home.local Once you've found your private ip, you can use that to connect to your server over your home network: // 192.168.50.132 is following the example, but you'll need to replace it with your own ip as shown in ipconfig / ifconfig
const response = await fetch('http://192.168.50.132:3000/poc3/convert', {
method: 'POST',
body: formData,
headers: { 'Accept': 'audio/mpeg' },
}); Couple of caveats with this approach:
I know networking can be confusing and it's generally not a skill set many developers have, it's more of a tertiary skill set. So I hope above helps, if not I can try to clarify anything that isn't clear. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
My question is simple.
I make a call using fetch in my CARDOVA app like so, from the ./www/js/index.js script:
I get this in the logs:
I know the API endpoint works 100%.
I know the system works with a fetch towards the prod URL endpoint (https://mywebsite/poc3/convert).
I think this fetch error is because I need to enable something from the config.xml file.
Below are all the versions and configs I am running:
Extra notes:
connect-src 'self' http://localhost:3000 https://mywebsite.com;
BELOW:
JS android xml webview android-webview
Added some "extra notes" about what I tried to resolve the issue to give reader an idea.
Beta Was this translation helpful? Give feedback.
All reactions