diff options
-rw-r--r-- | src/mixins/service.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/mixins/service.js b/src/mixins/service.js index abc708c..b47f756 100644 --- a/src/mixins/service.js +++ b/src/mixins/service.js | |||
@@ -1,3 +1,5 @@ | |||
1 | const merge = require("lodash.merge"); | ||
2 | |||
1 | export default { | 3 | export default { |
2 | props: { | 4 | props: { |
3 | proxy: Object, | 5 | proxy: Object, |
@@ -25,18 +27,28 @@ export default { | |||
25 | this.item.useCredentials === true ? "include" : "omit"; | 27 | this.item.useCredentials === true ? "include" : "omit"; |
26 | } | 28 | } |
27 | 29 | ||
28 | options = Object.assign(options, init); | 30 | if (this.proxy?.apikey) { |
31 | options.headers = { | ||
32 | "X-Homer-Api-Key": this.proxy.apikey, | ||
33 | }; | ||
34 | } | ||
29 | 35 | ||
30 | if (path.startsWith("/")) { | 36 | if (path.startsWith("/")) { |
31 | path = path.slice(1); | 37 | path = path.slice(1); |
32 | } | 38 | } |
33 | 39 | ||
34 | let url = this.endpoint; | 40 | let url = path ? `${this.endpoint}/${path}` : this.endpoint; |
35 | 41 | ||
36 | if (path) { | 42 | if (this.proxy?.url) { |
37 | url = `${this.endpoint}/${path}`; | 43 | options.headers = { |
44 | ...(options.headers || {}), | ||
45 | "X-Homer-Api-Url": url, | ||
46 | }; | ||
47 | url = this.proxy.url; | ||
38 | } | 48 | } |
39 | 49 | ||
50 | options = merge(options, init); | ||
51 | |||
40 | return fetch(url, options).then((response) => { | 52 | return fetch(url, options).then((response) => { |
41 | if (!response.ok) { | 53 | if (!response.ok) { |
42 | throw new Error("Not 2xx response"); | 54 | throw new Error("Not 2xx response"); |