Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my ngResource to accept custom headers?

Tags:

angularjs

My code in coffeescript :

  resource = $resource GlobalService.apiRoot + "stuffs", {},
    get:
      method: "GET"
      headers:
        "Accept": "application/stuffs;version=3"
        "Authorization": 'Token token="' + $.cookie('token') + '"'

My code in javascript :

var resource;

resource = $resource(GlobalService.apiRoot + "stuffs", {}, {
  get: {
    method: "GET",
    headers: {
      "Accept": "application/stuffs;version=3",
      "Authorization": 'Token token="' + $.cookie('token') + '"'
    }
  }
});

Then when I do..

resource.get ->

It doesn't send out those specified headers, and effectually fails the CORS authorization.

Any recommendations?

like image 764
Trip Avatar asked Oct 06 '22 02:10

Trip


1 Answers

Looks like that headers setting is only available in the latest "unstable" release of Angular. If you use this, be sure to upgrade both angular.js and angular.resource.js to 1.1.2 (current unstable release).

  • http://code.angularjs.org/1.1.2/angular.js
  • http://code.angularjs.org/1.1.2/angular-resource.js
like image 94
Ben Lesh Avatar answered Oct 13 '22 09:10

Ben Lesh