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