Cordova generated app have problems with the CORS


#1

Hi guys!,

I’m building an app that is using a simple scrapper. So i call the websites with the $http service. On development i use the proxies listed based on the documentation, so far in development works great, but when i’m building the app, it doesn’t matters if it is for android or iOS, it will throw the CORS exception and the error handler of $http is executed.

Here is the controller:

function signo($scope, $stateParams, $http, $ionicLoading, FortunaService, HOROSCOPOURL, SIGNOS) {
  $scope.signo = FortunaService.signo;
  $scope.fortuna = FortunaService.fortuna = _.find($scope.signo.fortuna, { 'id': parseInt($stateParams.id) });
  $scope.signo.textline = '';
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  });

  $http.get(HOROSCOPOURL + $scope.fortuna.url).then(function (xhr) {
    var parser = new DOMParser(),
        doc = parser.parseFromString(xhr.data, 'text/html'),
        textline = doc.getElementById('textline').innerHTML;
    
    textline = textline.replace(/<br>/g, '');
    $scope.signo.textline = textline;

    $ionicLoading.hide();

  }, function (error) {
  	console.log(JSON.stringify(error));
    $ionicLoading.hide();
  });
}

angular.module('starter')
  .controller('SignoCtrl', signo);

Any help to make this works would be appreciated it :smile: