Compare commits

...

5 Commits

Author SHA1 Message Date
Evan Steinkerchner
a4c1f6a37d Added forwarder binding to Service.vue 2022-04-28 20:08:42 -04:00
Evan Steinkerchner
76d30be8e3 Pass new forwarder config to services, give it a default value of empty 2022-04-19 20:37:38 -04:00
Evan Steinkerchner
240e3f0e87 Changed config and header names as per @bastienwirtz feedback 2022-04-19 20:24:51 -04:00
Evan Steinkerchner
33f75a798a Merge branch 'main' into proxy-api 2022-04-19 20:18:39 -04:00
Evan Steinkerchner
a2dfffab68 Added url and apikey config options under proxy 2022-03-20 16:32:24 -04:00
4 changed files with 28 additions and 6 deletions

View File

@ -84,6 +84,7 @@
:key="index"
:item="item"
:proxy="config.proxy"
:forwarder="config.forwarder"
:class="['column', `is-${12 / config.columns}`]"
/>
</template>
@ -113,6 +114,7 @@
:key="index"
:item="item"
:proxy="config.proxy"
:forwarder="config.forwarder"
/>
</div>
</div>

View File

@ -52,4 +52,5 @@ links: []
services: []
proxy: ~
proxy: ~
forwarder: ~

View File

@ -1,5 +1,10 @@
<template>
<component v-bind:is="component" :item="item" :proxy="proxy"></component>
<component
v-bind:is="component"
:item="item"
:proxy="proxy"
:forwarder="forwarder"
></component>
</template>
<script>
@ -10,6 +15,7 @@ export default {
props: {
item: Object,
proxy: Object,
forwarder: Object,
},
computed: {
component() {

View File

@ -1,6 +1,9 @@
const merge = require("lodash.merge");
export default {
props: {
proxy: Object,
forwarder: Object,
},
created: function () {
// custom service often consume info from an API using the item link (url) as a base url,
@ -25,18 +28,28 @@ export default {
this.item.useCredentials === true ? "include" : "omit";
}
options = Object.assign(options, init);
if (this.forwarder?.apikey) {
options.headers = {
"X-Homer-Forwarder-Api-Key": this.forwarder.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.forwarder?.url) {
options.headers = {
...(options.headers || {}),
"X-Homer-Forwarder-Url": url,
};
url = this.forwarder.url;
}
options = merge(options, init);
return fetch(url, options).then((response) => {
if (!response.ok) {
throw new Error("Not 2xx response");