<Service
v-for="(item, index) in group.items"
:key="index"
- v-bind:item="item"
+ :item="item"
+ :proxy="config.proxy"
:class="['column', `is-${12 / config.columns}`]"
/>
</template>
<Service
v-for="(item, index) in group.items"
:key="index"
- v-bind:item="item"
+ :item="item"
+ :proxy="config.proxy"
/>
</div>
</div>
message: ~
links: []
services: []
+
+
+proxy: ~
\ No newline at end of file
<template>
- <component v-bind:is="component" :item="item"></component>
+ <component v-bind:is="component" :item="item" :proxy="proxy"></component>
</template>
<script>
name: "Service",
props: {
item: Object,
+ proxy: Object,
},
computed: {
component() {
</template>
<script>
+import service from "@/mixins/service.js";
import Generic from "./Generic.vue";
export default {
name: "AdGuardHome",
+ mixins: [service],
props: {
item: Object,
},
},
methods: {
fetchStatus: async function () {
- this.status = await fetch(`${this.item.url}/control/status`, {
- credentials: "include",
- })
- .then((response) => response.json())
- .catch((e) => console.log(e));
+ this.status = await this.fetch("/control/status").catch((e) =>
+ console.log(e)
+ );
},
fetchStats: async function () {
- this.stats = await fetch(`${this.item.url}/control/stats`, {
- credentials: "include",
- })
- .then((response) => response.json())
- .catch((e) => console.log(e));
+ this.stats = await this.fetch("/control/stats").catch((e) =>
+ console.log(e)
+ );
},
},
};
--- /dev/null
+export default {
+ props: {
+ proxy: Object,
+ },
+ created: function () {
+ // custom service often consume info from an API using the item link (url) as a base url,
+ // but sometimes the base url is different. An optional alternative URL can be provided with the "endpoint" key.
+ this.endpoint = this.item.endpoint || this.item.url;
+ },
+ methods: {
+ fetch: function (path, init) {
+ let options = {};
+
+ if (this.proxy?.useCredentials) {
+ options.credentials = "include";
+ }
+
+ options = Object.assign(options, init);
+
+ return fetch(`${this.endpoint}/${path}`, options).then((response) => {
+ if (!response.ok) {
+ throw new Error("Not 2xx response");
+ }
+ return response.json();
+ });
+ },
+ },
+};