diff options
author | Evan Steinkerchner <esteinkerchner@gmail.com> | 2022-03-20 16:32:24 -0400 |
---|---|---|
committer | Evan Steinkerchner <esteinkerchner@gmail.com> | 2022-03-20 16:32:24 -0400 |
commit | a2dfffab6892c6976fc8b880f75c314506259675 (patch) | |
tree | 647b01924a5a2cf2ae44387968c52b54bdf612f2 /src/mixins | |
parent | 775d0a8e862247bc78a53d6cf0ceef5651d4f98c (diff) | |
download | homer-a2dfffab6892c6976fc8b880f75c314506259675.tar.gz homer-a2dfffab6892c6976fc8b880f75c314506259675.tar.zst homer-a2dfffab6892c6976fc8b880f75c314506259675.zip |
Added url and apikey config options under proxy
Diffstat (limited to 'src/mixins')
-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"); |