Improve ping service

This commit is contained in:
Bastien Wirtz 2021-07-14 15:49:19 +02:00
parent 92d899bd48
commit 3a8fa151f4
2 changed files with 19 additions and 14 deletions

View File

@ -83,13 +83,13 @@ export default {
&.enabled:before { &.enabled:before {
background-color: #94e185; background-color: #94e185;
border-color: #78d965; border-color: #78d965;
box-shadow: 0 0 4px 1px #94e185; box-shadow: 0 0 5px 1px #94e185;
} }
&.disabled:before { &.disabled:before {
background-color: #c9404d; background-color: #c9404d;
border-color: #c42c3b; border-color: #c42c3b;
box-shadow: 0 0 4px 1px #c9404d; box-shadow: 0 0 5px 1px #c9404d;
} }
&:before { &:before {

View File

@ -22,8 +22,8 @@
</template> </template>
</p> </p>
</div> </div>
<div v-if="api" class="status" :class="api.status"> <div v-if="status" class="status" :class="status">
{{ api.status }} {{ status }}
</div> </div>
</div> </div>
<div class="tag" :class="item.tagstyle" v-if="item.tag"> <div class="tag" :class="item.tagstyle" v-if="item.tag">
@ -42,9 +42,7 @@ export default {
item: Object, item: Object,
}, },
data: () => ({ data: () => ({
api: { status: null,
status: "",
},
}), }),
created() { created() {
this.fetchStatus(); this.fetchStatus();
@ -52,9 +50,16 @@ export default {
methods: { methods: {
fetchStatus: async function () { fetchStatus: async function () {
const url = `${this.item.url}`; const url = `${this.item.url}`;
this.api.status = await fetch(url) fetch(url, { method: "HEAD", cache: "no-cache" })
.then(() => "enabled") .then((response) => {
.catch(() => "disabled"); if (!response.ok) {
throw Error(response.statusText);
}
this.status = "online";
})
.catch(() => {
this.status = "offline";
});
}, },
}, },
}; };
@ -68,16 +73,16 @@ export default {
font-size: 0.8rem; font-size: 0.8rem;
color: var(--text-title); color: var(--text-title);
&.enabled:before { &.online:before {
background-color: #94e185; background-color: #94e185;
border-color: #78d965; border-color: #78d965;
box-shadow: 0 0 4px 1px #94e185; box-shadow: 0 0 5px 1px #94e185;
} }
&.disabled:before { &.offline:before {
background-color: #c9404d; background-color: #c9404d;
border-color: #c42c3b; border-color: #c42c3b;
box-shadow: 0 0 4px 1px #c9404d; box-shadow: 0 0 5px 1px #c9404d;
} }
&:before { &:before {