@@ -72,6 +72,7 @@ export default {
72
72
statusCheckHeaders: Object ,
73
73
statusCheckUrl: String ,
74
74
statusCheckInterval: Number ,
75
+ statusCheckAllowInsecure: Boolean ,
75
76
},
76
77
data () {
77
78
return {
@@ -144,18 +145,33 @@ export default {
144
145
default : return ' "\\ f054"' ;
145
146
}
146
147
},
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);
149
154
this .statusResponse = undefined ;
155
+ // Find base URL, where the API is hosted
150
156
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)
155
171
.then ((response ) => {
156
172
if (response .data ) this .statusResponse = response .data ;
157
173
})
158
- .catch (() => {
174
+ .catch (() => { // Something went very wrong.
159
175
this .statusResponse = {
160
176
statusText: ' Failed to make request' ,
161
177
statusSuccess: false ,
0 commit comments