Skip to content

Instantly share code, notes, and snippets.

@seifsallam
Last active August 15, 2016 19:37
Show Gist options
  • Save seifsallam/5845028 to your computer and use it in GitHub Desktop.
Save seifsallam/5845028 to your computer and use it in GitHub Desktop.
Ember RESTAdapter configuration for sending HTTP header and CrossDomain Access
// store.js
App.Adapter = DS.RESTAdapter.reopen({
bulkCommit: false,
url: 'http://localhost:5000',
namespace: 'api',
corsWithCredentials: true,
headers: {
'Accept': 'application/vnd.vendor+json;version=1',
'Content-type': 'application/json',
'x-vendor-appid': '123',
'x-vendor-secret': '12345'
},
ajax: function(url, type, hash) {
if (this.headers !== undefined) {
var headers = this.headers;
if (hash) {
hash.beforeSend = function (xhr) {
Ember.keys(headers).forEach(function(key) {
xhr.setRequestHeader(key, headers[key]);
});
};
}
}
return this._super(url, type, hash);
}
});
// Add maping and extra configuration here before you create the object
App.Store = DS.Store.extend({
adapter: App.Adapter.create()
});
App.store = App.Store.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment