-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic-v1.js
38 lines (32 loc) · 1.06 KB
/
basic-v1.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
// HTML Embed for cState
// Version 1.0
// github.com/cstate/html-embed
// Variables
// Site + '/index.json'
var cStateAPIRoot = 'https://flamboyant-shirley-6bc75e.netlify.app/index.json'
var cStateEmbedPrefix = '[cState HTML Embed v1.0] ';
var cStateEmbedDebugging = false;
var cStateAPIStatus = 'tryingToGetStatus';
// Code itself
fetch(cStateAPIRoot)
.then(
function(response) {
if (response.status !== 200) {
console.log(cStateEmbedPrefix + 'API not OK, it sent HTTP status code ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
// When debugging, this code should be run to see API response
if (cStateEmbedDebugging) {
console.log(cStateEmbedPrefix + 'API response: ', data);
cStateAPIStatus = data.summaryStatus;
console.log(cStateEmbedPrefix + 'API says status page is: ' + cStateAPIStatus);
}
});
}
)
.catch(function(err) {
console.log('Fetch error :-S', err);
});