-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
46 lines (43 loc) · 1.67 KB
/
index.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
<html>
<head>
<link rel="stylesheet" href="/style">
<title>nikos lil pinger example app</title>
<script>
async function pingAdress(host) {
// sender vores host-name til express serveren
const response = await fetch('http://localhost:3000/ping', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ host: host })
});
if(response.status !== 200) {
throw new Error('/ping returned status code ' + response.status);
}
const jsonBody = await response.json()
return jsonBody.elapsed
}
async function run() {
const address = document.getElementById('pingInput').value;
try {
// fetch kaldet til /ping
const rtt = await pingAdress(address)
document.getElementById('pingError').innerHTML = '';
document.getElementById('pingResult').innerHTML = 'Round trip time for ' + address + ': ' + rtt;
} catch (error) {
document.getElementById('pingError').innerHTML = error;
}
}
</script>
</head>
<body>
<h1>http(s) pinger example</h1>
<input name="host" placeholder="arto.dk" id="pingInput" />
<button onclick="run()">
Ping
</button>
<p id="pingResult"></p>
<p id="pingError" style="color:red"></p>
</body>
</html>