From f343af3b002e3d9992abc759946c1c053e977350 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Thu, 26 Aug 2021 22:18:21 +0100 Subject: [PATCH] :sparkles: Re: #181 Adds option to ignore SSL in ping --- src/components/LinkItems/Item.vue | 30 +++++++++++++++++++++------- src/components/LinkItems/Section.vue | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/LinkItems/Item.vue b/src/components/LinkItems/Item.vue index 1a33a818..0177d886 100644 --- a/src/components/LinkItems/Item.vue +++ b/src/components/LinkItems/Item.vue @@ -72,6 +72,7 @@ export default { statusCheckHeaders: Object, statusCheckUrl: String, statusCheckInterval: Number, + statusCheckAllowInsecure: Boolean, }, data() { return { @@ -144,18 +145,33 @@ export default { default: return '"\\f054"'; } }, + /* Pulls together all user options, returns URL + Get params for ping endpoint */ + makeApiUrl() { + const { + url, statusCheckUrl, statusCheckHeaders, statusCheckAllowInsecure, + } = this; + const encode = (str) => encodeURIComponent(str); + this.statusResponse = undefined; + // Find base URL, where the API is hosted + const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin; + // Find correct URL to check, and encode + const urlToCheck = `?&url=${encode(statusCheckUrl || url)}`; + // Get, stringify and encode any headers + const headers = statusCheckHeaders + ? `&headers=${encode(JSON.stringify(statusCheckHeaders))}` : ''; + // Deterimine if user disabled security + const enableInsecure = statusCheckAllowInsecure ? '&enableInsecure=true' : ''; + // Construct the full API endpoint's URL with GET params + return `${baseUrl}/ping/${urlToCheck}${headers}${enableInsecure}`; + }, /* Checks if a given service is currently online */ checkWebsiteStatus() { - this.statusResponse = undefined; - const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin; - const urlToCheck = this.statusCheckUrl || this.url; - const headers = this.statusCheckHeaders || {}; - const endpoint = `${baseUrl}/ping?url=${urlToCheck}`; - axios.get(endpoint, { headers }) + const endpoint = this.makeApiUrl(); + axios.get(endpoint) .then((response) => { if (response.data) this.statusResponse = response.data; }) - .catch(() => { + .catch(() => { // Something went very wrong. this.statusResponse = { statusText: 'Failed to make request', statusSuccess: false, diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue index f9bc3afa..c88ad459 100644 --- a/src/components/LinkItems/Section.vue +++ b/src/components/LinkItems/Section.vue @@ -33,6 +33,7 @@ :hotkey="item.hotkey" :enableStatusCheck="shouldEnableStatusCheck(item.statusCheck)" :statusCheckInterval="getStatusCheckInterval()" + :statusCheckAllowInsecure="item.statusCheckAllowInsecure" @itemClicked="$emit('itemClicked')" @triggerModal="triggerModal" />