-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_main.js
59 lines (53 loc) · 2.01 KB
/
_main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var startupdelay = 5;
var timeout = 10;
var repeatinterval = 10;
// Function to check URL and redirect if we get 200 status
function checkURL(url) {
console.log("[INFO] Starting to check connectivity to \"" + url + "\"");
// Fire test request
// (We use a Heroku hosted proxy that injects the actual HTTP status code as well as the website content, encoded in JSON
// You can find the source in the following repository: https://github.com/yeahwhat-mc/heroku-php-status-proxy )
$.ajax('https://yeahwhat-proxy.herokuapp.com/?url=' + url, {
type: "GET",
dataType: "html",
timeout: timeout * 1000,
// In case of 404, disable spinner and show outage info again
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("[ERROR] Proxy returned unexpected response. Check request for further information.");
},
// In case of 200, disable spinner and redirect back to working website
success: function(data) {
var json = jQuery.parseJSON(data);
if (json.status.http_code == "200") {
console.log("[INFO] Site seems available again. Trying to redirect ...");
location.href = url;
} else {
console.log("[ERROR] Still down. Recheck in " + repeatinterval + " seconds ...");
}
}
});
}
// If jQuery is loaded, parse hash to store the subdomain
$(document).ready(function(){
var subdomain, fulldomain;
if(window.location.hash) {
subdomain = window.location.hash.substring(1);
} else {
subdomain = 'www';
}
// Generate FQDN
fulldomain = subdomain + '.yeahwh.at';
// If subdomain is not "www"
if (subdomain != 'www') {
// Replace span with hash ...
$('span').text('Our ' + subdomain);
// ... and substitute title
$('title').text(subdomain + ' - ' + $('title').text());
}
// Delay first execution, then run checkURL function every repeatinterval seconds
setTimeout(function() {
setInterval(function() {
checkURL('http://' + fulldomain);
}, repeatinterval * 1000);
}, startupdelay * 1000);
});