]>
git.immae.eu Git - github/bastienwirtz/homer.git/blob - src/mixins/service.js
6 // custom service often consume info from an API using the item link (url) as a base url,
7 // but sometimes the base url is different. An optional alternative URL can be provided with the "endpoint" key.
8 this.endpoint
= this.item
.endpoint
|| this.item
.url
;
10 if (this.endpoint
.endsWith("/")) {
11 this.endpoint
= this.endpoint
.slice(0, -1);
15 fetch: function (path
, init
, json
= true) {
18 if (this.proxy
?.useCredentials
) {
19 options
.credentials
= "include";
22 // Each item can override the credential settings
23 if (this.item
.useCredentials
!== undefined) {
25 this.item
.useCredentials
=== true ? "include" : "omit";
28 options
= Object
.assign(options
, init
);
30 if (path
.startsWith("/")) {
34 return fetch(`${this.endpoint}/${path}`, options
).then((response
) => {
36 throw new Error("Not 2xx response");
39 return json
? response
.json() : response
;