This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
54 lines (46 loc) · 1.63 KB
/
test.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>viewcounter test page</title>
</head>
<body>
<h4>Local (<span id="local_url"></span>)</h4>
<span id="local_results"></span>
<h4>Production (<span id="production_url"></span>)</h4>
<span id="production_results"></span>
<script type="text/javascript">
const LocalURL = 'http://localhost:8080/';
const ProductionURL = 'https://us-central1-ut-dts-agrc-gis-utah-gov-prod.cloudfunctions.net/viewcounter';
const makeRequest = async function (url, resultsSpan, urlSpan) {
const startTime = Date.now();
const response = await fetch(url, {
method: 'POST',
body: `${location.origin}${location.pathname}`,
});
if (response.status !== 200) {
resultsSpan.innerHTML = `Response code: ${response.status}`;
}
try {
const responseJson = await response.json();
if (responseJson.count) {
resultsSpan.innerHTML = `This page has been viewed ${responseJson.count.toLocaleString()} times (${
Date.now() - startTime
}ms).`;
} else {
resultsSpan.innerHTML = JSON.stringify(responseJson);
}
} catch {
resultsSpan.innerHTML = response;
}
urlSpan.innerHTML = url;
};
makeRequest(LocalURL, document.getElementById('local_results'), document.getElementById('local_url'));
makeRequest(
ProductionURL,
document.getElementById('production_results'),
document.getElementById('production_url'),
);
</script>
</body>
</html>