Ionic 2 CORS

when making an http.get call I receive the following error… “Redirect was blocked for CORS request.”. I have the whitelist plugin installed and my config.xml file is as such. Any advice would be great !! Thank you !!

   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <widget id="com.ionicframework.ionic2test118838" version="0.0.1" xmlns="http://www.w3.org/ns/widgets"    xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>Ionic2Test</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
  <content src="index.html"/>
  <access origin="*"/>
  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>
  <platform name="android">
    <allow-intent href="market:*"/>
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
  </platform>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashMaintainAspectRatio" value="true"/>
  <preference name="FadeSplashScreenDuration" value="300"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
  <plugin name="cordova-plugin-whitelist" spec="1.3.1"/>
  <plugin name="cordova-plugin-console" spec="1.0.5"/>
  <plugin name="cordova-plugin-statusbar" spec="2.2.1"/>
  <plugin name="cordova-plugin-device" spec="1.1.4"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/>
</widget>

you can also install https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
if testing in chrome

1 Like

I have tried creating a proxy. Do you have advice on how to use it? It wont carry in the url from proxy

        this.http.get('/api' + '/prehearing').map(res => res.json()).subscribe(data => {
            console.log(data);
        });

how have you added the proxy?

 I am poiinting to a firebase database.  I have a base URL in the proxy and append to it in the call.  

 {
  "name": "Ionic2Test",
  "app_id": "",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "myurl"
    }
  ]
}


    this.http.get('/api' + '/prehearing').map(res => res.json()).subscribe(data => {
        console.log(data);
    });

I had to put base url as localhost:8100 in my http requests…not just the proxy extensiob