X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fmixins%2Fservice.js;h=abc708c9d326549aa74ab4ac330e92bd49f3ca3e;hb=585844394d7a4cc4a58e30fd42cb1f8e83ac02f7;hp=ae23a2742bc5130fc4f08b9a16ab92192afa3f85;hpb=efc2bbb85673fb269e75d64655e433bed90a995a;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/mixins/service.js b/src/mixins/service.js index ae23a27..abc708c 100644 --- a/src/mixins/service.js +++ b/src/mixins/service.js @@ -12,7 +12,7 @@ export default { } }, methods: { - fetch: function (path, init) { + fetch: function (path, init, json = true) { let options = {}; if (this.proxy?.useCredentials) { @@ -31,11 +31,18 @@ export default { path = path.slice(1); } - return fetch(`${this.endpoint}/${path}`, options).then((response) => { + let url = this.endpoint; + + if (path) { + url = `${this.endpoint}/${path}`; + } + + return fetch(url, options).then((response) => { if (!response.ok) { throw new Error("Not 2xx response"); } - return response.json(); + + return json ? response.json() : response; }); }, },