Skip to content

Commit 9c18d9b

Browse files
authored
Merge pull request #32 from catarse/adds_global_header
Adds global header wrapper option
2 parents fecd505 + 702491d commit 9c18d9b

5 files changed

+20
-12
lines changed

dist/mithril-postgrest.js

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mithril-postgrest.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-postgrest.umd.js

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/init.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export default describe("postgrest.init & postgrest.request", function(){
1212

1313
it("should append api prefix used on init to request url", function(){
1414
postgrest.request({method: "GET", url: "pages.json"});
15-
expect(m.request).toHaveBeenCalledWith({method: "GET", url: apiPrefix + "pages.json", extract: jasmine.any(Function)});
15+
expect(m.request).toHaveBeenCalledWith({method: "GET", url: apiPrefix + "pages.json", extract: jasmine.any(Function), config: jasmine.any(Function)});
1616
});
1717
});

src/postgrest.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Postgrest () {
5555

5656
postgrest.token = token;
5757

58-
postgrest.init = (apiPrefix, authenticationOptions) => {
58+
postgrest.init = (apiPrefix, authenticationOptions, globalHeader = {}) => {
5959
postgrest.request = (options) => {
6060
const errorHandler = (xhr) => {
6161
try {
@@ -70,9 +70,13 @@ function Postgrest () {
7070
});
7171
}
7272
};
73-
return m.request(_.extend({extract: errorHandler}, options, {
74-
url: apiPrefix + options.url
75-
}));
73+
return m.request(
74+
addConfigHeaders(globalHeader,
75+
_.extend({extract: errorHandler}, options, {
76+
url: apiPrefix + options.url
77+
})
78+
)
79+
);
7680
};
7781

7882
postgrest.authenticate = () => {

0 commit comments

Comments
 (0)