From a2dfffab6892c6976fc8b880f75c314506259675 Mon Sep 17 00:00:00 2001 From: Evan Steinkerchner Date: Sun, 20 Mar 2022 16:32:24 -0400 Subject: Added url and apikey config options under proxy --- src/mixins/service.js | 20 ++++++++++++++++---- 1 file 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 @@ +const merge = require("lodash.merge"); + export default { props: { proxy: Object, @@ -25,18 +27,28 @@ export default { this.item.useCredentials === true ? "include" : "omit"; } - options = Object.assign(options, init); + if (this.proxy?.apikey) { + options.headers = { + "X-Homer-Api-Key": this.proxy.apikey, + }; + } if (path.startsWith("/")) { path = path.slice(1); } - let url = this.endpoint; + let url = path ? `${this.endpoint}/${path}` : this.endpoint; - if (path) { - url = `${this.endpoint}/${path}`; + if (this.proxy?.url) { + options.headers = { + ...(options.headers || {}), + "X-Homer-Api-Url": url, + }; + url = this.proxy.url; } + options = merge(options, init); + return fetch(url, options).then((response) => { if (!response.ok) { throw new Error("Not 2xx response"); -- cgit v1.2.3