Search code examples
javascriptangularjshttpgetrestangular

Restangular sending OPTIONS method before GET


I'm working with an API that only accepts the GET method and restricts the use of the OPTIONS. When I send requests in chrome (bypassing cors via --disable-web-security) it sends the OPTIONS method right before the GET method preventing the resources from being obtained.

In Safari, however, I can obtain the resource as it only sends a GET. Im testing on mobile through the ionic framework and I cannot get it get the resources, Im assuming the OPTIONS is what's causing this. I've tried creating a custom request and though this, this and this and the docs would help but I haven't been having any luck. This is what my code looks like, I just started using Restangular and still figuring it out and any help/tips is appreciated. Thanks.

      .constant('baseURL', {
          url: 'https://api.example.com'
      })

      .config([
  'RestangularProvider', 'baseURL',
  function(RestangularProvider, baseURL) {

    RestangularProvider.setBaseUrl(baseURL.url);


    RestangularProvider.setDefaultHeaders({
      Authorization: 'Basic ' + baseURL.jwt
    })

  }
])


      .controller('MainCtrl', ['$scope', 'Restangular',
          function($scope, Restangular) {

              Restangular.one('destinations').get('').then(function(destinations) {

      $scope.destinationBase = destinations;

    });

Solution

  • I figured it out, I hadn't ever worked with preflight issues and thats what this was. I just opened my browser set to disable cors