Reputation: 75
using ember 1.13.2 with ember data 1.13.4 in conjunction with a rails backend.
according to the ember guides, the following statement should modify the http headers for every XHR request:
App.ApplicationAdapter = DS.RESTAdapter.extend({
headers: {
"Authorization": "secret key"
}
});
so I added this as coffee script to my application
App.ApplicationAdapter = DS.RESTAdapter.extend
headers: {
"Authorization": "foofoo"
}
and it's included and correctly compiled to javascript.
But the http header isn't extended with the new header at all.
http://discuss.emberjs.com/t/passing-header-information-to-rest-get-request-using-restadapter/4220/8
The only solution that works is the one with configuring jquery ajax:
Ember.$.ajaxPrefilter(function(options, oriOpt, jqXHR) {
jqXHR.setRequestHeader("someHeader", "someValue");
});
But I would prefer the ember way
Update:
Strange, it now just works with the ember way. just restarted my computer. maybe this was a browser cache issue.
Upvotes: 1
Views: 144
Reputation: 2257
As per the Ember docs, you seem to be mostly correct. Here's the solution that ought to work, courtesy of Ember documentation
Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary headers can be set as key/value pairs on the RESTAdapter's headers property and Ember Data will send them along with each ajax request.
App.ApplicationAdapter = DS.RESTAdapter.extend({
headers: {
'API_KEY': 'secret key',
'ANOTHER_HEADER': 'Some header value',
'AUTHORIZATION': 'secret key'
}
});
Upvotes: 1