forked from extern/homer
Allow any service to override the credentials option
This commit is contained in:
parent
fea0f09045
commit
efc2bbb856
@ -26,7 +26,7 @@ connectivityCheck: true # whether you want to display a message when the apps ar
|
|||||||
|
|
||||||
# Optional: Proxy / hosting option
|
# Optional: Proxy / hosting option
|
||||||
proxy:
|
proxy:
|
||||||
useCredentials: false # send cookies & authorization headers when fetching service specific data. Set to `true` if you use an authentication proxy.
|
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.
|
||||||
|
|
||||||
# Optional theming
|
# Optional theming
|
||||||
theme: default # 'default' or one of the themes available in 'src/assets/themes'.
|
theme: default # 'default' or one of the themes available in 'src/assets/themes'.
|
||||||
|
@ -6,6 +6,10 @@ export default {
|
|||||||
// custom service often consume info from an API using the item link (url) as a base url,
|
// custom service often consume info from an API using the item link (url) as a base url,
|
||||||
// but sometimes the base url is different. An optional alternative URL can be provided with the "endpoint" key.
|
// but sometimes the base url is different. An optional alternative URL can be provided with the "endpoint" key.
|
||||||
this.endpoint = this.item.endpoint || this.item.url;
|
this.endpoint = this.item.endpoint || this.item.url;
|
||||||
|
|
||||||
|
if (this.endpoint.endsWith("/")) {
|
||||||
|
this.endpoint = this.endpoint.slice(0, -1);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetch: function (path, init) {
|
fetch: function (path, init) {
|
||||||
@ -15,8 +19,18 @@ export default {
|
|||||||
options.credentials = "include";
|
options.credentials = "include";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each item can override the credential settings
|
||||||
|
if (this.item.useCredentials !== undefined) {
|
||||||
|
options.credentials =
|
||||||
|
this.item.useCredentials === true ? "include" : "omit";
|
||||||
|
}
|
||||||
|
|
||||||
options = Object.assign(options, init);
|
options = Object.assign(options, init);
|
||||||
|
|
||||||
|
if (path.startsWith("/")) {
|
||||||
|
path = path.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
return fetch(`${this.endpoint}/${path}`, options).then((response) => {
|
return fetch(`${this.endpoint}/${path}`, options).then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Not 2xx response");
|
throw new Error("Not 2xx response");
|
||||||
|
Loading…
Reference in New Issue
Block a user