Search code examples
cordovaionic-frameworkcorscordova-plugins

cordova-plugin-whitelist issue? 'Access Control Origin Cannot contain more than one origin' after upgrading cordova, ionic


I have built 40+ apps based on the same code in cordova/ionic that work fine. Then I updated my local environment (latest npm, node, ionic, cordova). When I test my apps in the local browser (ionic serve) they run fine. When I build them and deploy on my test device, all of the ajax calls to MY server fail with:

 Access Control Origin Cannot contain more than one origin. 

The ajax calls to 2 other API domains are fine. I have not changed anything on my server and the older binaries still work fine. When I examine the safari developer panel it shows that error but says no header information was returned from the server, so I can't get any visibility on what headers are being rejected. I run a global search on my PHP server code and all I see is the standard access headers.

    header('Access-Control-Allow-Origin: *');
    header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS");

My index.html also has the meta tag

<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">

Config.xml contains

<access origin="*" />
<plugin name="cordova-plugin-whitelist" spec="1.0.0" />

I haven't changed anything on the server (the other non-upgraded xcode binaries do not have this issue) so the error must be coming from the internal ajax proxy resolve in the upgraded code.

What else can I try? How can I see what origin headers are being found and rejected?


Solution

  • I don't fully understand why this triggered an error now and not before BUT I found an .htaccess file in my /home directory on the server with an access-header directive for fonts.

    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
    

    I commented that out and now my ajax calls are working with my updated code.