Skip to content

Commit

Permalink
+ default headers on module bootstrap
Browse files Browse the repository at this point in the history
*Added method "setHeaders" in module config, this will set global headers for all requests which cannot be overriden

resolves #3
  • Loading branch information
oscarr-reyes committed May 7, 2017
1 parent c883838 commit 52e86e5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
18 changes: 13 additions & 5 deletions dist/ngRestful.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
*/
ngRestful.constant("ngRestful", {
$domain: "",
$headers: {},
setDomain: function(value) {
this.$domain = value;
},
setHeader: function(key, value) {
this.$headers[key] = value;
}
});

Expand Down Expand Up @@ -136,7 +140,7 @@
return resource;
}]);

ngRestful.service("$restful", ["$http", function($http) {
ngRestful.service("$restful", ["$http", "ngRestful", function($http, $globals) {
/**
* Performs a GET request to the host
*
Expand Down Expand Up @@ -207,6 +211,14 @@
// Merge config data into request object
Object.assign(request, config);

// Check if headers is defined, if otherwise then create object
if (typeof request.headers == "undefined") {
request.headers = {};
}

// Merge default headers into header request object
Object.assign(request.headers, $globals.$headers);

// Create custom object for attached files
if (method != "GET" && this.hasFileObject(data)) {
var form = new FormData();
Expand All @@ -215,10 +227,6 @@
form.append(prop, data[prop]);
}

if (typeof request.headers == "undefined") {
request.headers = {};
}

// let the broswer handle the content-type request
request.headers["Content-Type"] = undefined;

Expand Down
2 changes: 1 addition & 1 deletion dist/ngRestful.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 52e86e5

Please sign in to comment.