aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBastien Wirtz <bastien.wirtz@gmail.com>2021-10-10 10:16:18 +0200
committerBastien Wirtz <bastien.wirtz@gmail.com>2021-10-10 10:16:18 +0200
commitefc2bbb85673fb269e75d64655e433bed90a995a (patch)
tree6a2649fe921adfa54dc5ce8389462122e072bb6a
parentfea0f0904537db7ca164b1cb29ffcfcbb807a709 (diff)
downloadhomer-efc2bbb85673fb269e75d64655e433bed90a995a.tar.gz
homer-efc2bbb85673fb269e75d64655e433bed90a995a.tar.zst
homer-efc2bbb85673fb269e75d64655e433bed90a995a.zip
Allow any service to override the credentials option
-rw-r--r--docs/configuration.md2
-rw-r--r--src/mixins/service.js14
2 files changed, 15 insertions, 1 deletions
diff --git a/docs/configuration.md b/docs/configuration.md
index b1cce56..0dd0a85 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -26,7 +26,7 @@ connectivityCheck: true # whether you want to display a message when the apps ar
26 26
27# Optional: Proxy / hosting option 27# Optional: Proxy / hosting option
28proxy: 28proxy:
29 useCredentials: false # send cookies & authorization headers when fetching service specific data. Set to `true` if you use an authentication proxy. 29 useCredentials: false # send cookies & authorization headers when fetching service specific data. Set to `true` if you use an authentication proxy. Can be overrided on service level.
30 30
31# Optional theming 31# Optional theming
32theme: default # 'default' or one of the themes available in 'src/assets/themes'. 32theme: default # 'default' or one of the themes available in 'src/assets/themes'.
diff --git a/src/mixins/service.js b/src/mixins/service.js
index 99d8c01..ae23a27 100644
--- a/src/mixins/service.js
+++ b/src/mixins/service.js
@@ -6,6 +6,10 @@ export default {
6 // custom service often consume info from an API using the item link (url) as a base url, 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. 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; 8 this.endpoint = this.item.endpoint || this.item.url;
9
10 if (this.endpoint.endsWith("/")) {
11 this.endpoint = this.endpoint.slice(0, -1);
12 }
9 }, 13 },
10 methods: { 14 methods: {
11 fetch: function (path, init) { 15 fetch: function (path, init) {
@@ -15,8 +19,18 @@ export default {
15 options.credentials = "include"; 19 options.credentials = "include";
16 } 20 }
17 21
22 // Each item can override the credential settings
23 if (this.item.useCredentials !== undefined) {
24 options.credentials =
25 this.item.useCredentials === true ? "include" : "omit";
26 }
27
18 options = Object.assign(options, init); 28 options = Object.assign(options, init);
19 29
30 if (path.startsWith("/")) {
31 path = path.slice(1);
32 }
33
20 return fetch(`${this.endpoint}/${path}`, options).then((response) => { 34 return fetch(`${this.endpoint}/${path}`, options).then((response) => {
21 if (!response.ok) { 35 if (!response.ok) {
22 throw new Error("Not 2xx response"); 36 throw new Error("Not 2xx response");