Skip to content

Commit f343af3

Browse files
committed
✨ Re: gchq#181 Adds option to ignore SSL in ping
1 parent e755783 commit f343af3

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/components/LinkItems/Item.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default {
7272
statusCheckHeaders: Object,
7373
statusCheckUrl: String,
7474
statusCheckInterval: Number,
75+
statusCheckAllowInsecure: Boolean,
7576
},
7677
data() {
7778
return {
@@ -144,18 +145,33 @@ export default {
144145
default: return '"\\f054"';
145146
}
146147
},
147-
/* Checks if a given service is currently online */
148-
checkWebsiteStatus() {
148+
/* Pulls together all user options, returns URL + Get params for ping endpoint */
149+
makeApiUrl() {
150+
const {
151+
url, statusCheckUrl, statusCheckHeaders, statusCheckAllowInsecure,
152+
} = this;
153+
const encode = (str) => encodeURIComponent(str);
149154
this.statusResponse = undefined;
155+
// Find base URL, where the API is hosted
150156
const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
151-
const urlToCheck = this.statusCheckUrl || this.url;
152-
const headers = this.statusCheckHeaders || {};
153-
const endpoint = `${baseUrl}/ping?url=${urlToCheck}`;
154-
axios.get(endpoint, { headers })
157+
// Find correct URL to check, and encode
158+
const urlToCheck = `?&url=${encode(statusCheckUrl || url)}`;
159+
// Get, stringify and encode any headers
160+
const headers = statusCheckHeaders
161+
? `&headers=${encode(JSON.stringify(statusCheckHeaders))}` : '';
162+
// Deterimine if user disabled security
163+
const enableInsecure = statusCheckAllowInsecure ? '&enableInsecure=true' : '';
164+
// Construct the full API endpoint's URL with GET params
165+
return `${baseUrl}/ping/${urlToCheck}${headers}${enableInsecure}`;
166+
},
167+
/* Checks if a given service is currently online */
168+
checkWebsiteStatus() {
169+
const endpoint = this.makeApiUrl();
170+
axios.get(endpoint)
155171
.then((response) => {
156172
if (response.data) this.statusResponse = response.data;
157173
})
158-
.catch(() => {
174+
.catch(() => { // Something went very wrong.
159175
this.statusResponse = {
160176
statusText: 'Failed to make request',
161177
statusSuccess: false,

src/components/LinkItems/Section.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
:hotkey="item.hotkey"
3434
:enableStatusCheck="shouldEnableStatusCheck(item.statusCheck)"
3535
:statusCheckInterval="getStatusCheckInterval()"
36+
:statusCheckAllowInsecure="item.statusCheckAllowInsecure"
3637
@itemClicked="$emit('itemClicked')"
3738
@triggerModal="triggerModal"
3839
/>

0 commit comments

Comments
 (0)