Added url and apikey config options under proxy

This commit is contained in:
Evan Steinkerchner 2022-03-20 16:32:24 -04:00
parent 775d0a8e86
commit a2dfffab68

View File

@ -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");