My question is simple.
I make a call using fetch in my CORDOVA app like so, from the ./www/js/index.js script:
const response = await fetch('http://localhost:3000/poc3/convert', {
method: 'POST',
body: formData,
headers: { 'Accept': 'audio/mpeg' },
});
I get this in the logs:
Error: TypeError: Failed to fetch
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:
Cordova Packages:
cli: 12.0.0
common: 5.0.1
create: 5.0.0
lib: 12.0.2
common: 5.0.1
fetch: 4.0.0
serve: 4.0.1
Project Installed Platforms:
android: 14.0.0
Project Installed Plugins:
cordova-plugin-advanced-http: 3.3.1
cordova-plugin-file: 8.1.3
cordova-plugin-file-transfer: 2.0.0
Environment:
OS: Ventura 13.1 (22C65) (darwin 22.2.0) x64
Node: v18.19.0
npm: 10.2.3
android Environment:
android:
[=======================================] 100% Fetch remote repository...
Available Android targets:
----------
id: 1 or "android-35"
Name: Android API 35, extension level 13
Type: Platform
API level: 35
Revision: 2
Project Setting Files:
config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.mywebsite" version="1.0.0" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>mywebsite</name>
<description>Sample Apache Cordova App</description>
<author email="[email protected]" href="https://cordova.apache.org">
Apache Cordova Team
</author>
<content src="index.html" />
<allow-intent href="https://mywebsite.com/*" />
<!-- Localhost API calls enabled in development for testing search code: #000 for all enables -->
<access origin="http://localhost:3000" />
<!-- <access origin="http://*/*" /> -->
<access origin="https://mywebsite.com" />
<allow-navigation href="https://mywebsite.com/*" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
<preference name="AndroidExtraFilesystems" value="files,files-external,cache" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
android:maxSdkVersion="30" />
</config-file>
</platform>
</widget>
package.json:
--- Start of Cordova JSON Snippet ---
{
"platforms": [
"android"
],
"plugins": {
"cordova-plugin-file": {
"ANDROIDX_WEBKIT_VERSION": "1.4.0"
},
"cordova-plugin-advanced-http": {
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
},
"cordova-plugin-file-transfer": {}
}
}
--- End of Cordova JSON Snippet ---
Extra notes:
- The HTML meta is set like so:
connect-src 'self' http://localhost:3000 https://mywebsite.com; - I tried to editing the inner configuration files in .xml in these files: ./platforms/android/app/src/main/AndroidManifest.xml and ./platforms/android/app/src/main/res/xml/config.xml, but the build process RESETS the configurations to DEFAULT. (no effect)
- I tried to add BELOW in the main ./config.xml. And it did not work either
BELOW:
<!-- #000 -->
<!-- <allow-navigation href="http://localhost:3007/*" />
<allow-intent href="http://localhost:3007/*" />
<preference name="AndroidInsecureFileModeEnabled" value="true" /> -->
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
android:maxSdkVersion="30" />
<!-- #000 -->
<!-- <application android:usesCleartextTraffic="true" /> -->
</config-file>
<!-- #000 -->
<!-- <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config> -->
<!-- #000 -->
<!-- <config-file parent="/*" target="res/xml/config.xml">
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
</config-file> -->
</platform>