-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.html
73 lines (65 loc) · 1.63 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Fake JSON Server</title>
<style type="text/css">
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<div>
<h3>Collections found:</h3>
{{ collections }}
</div>
<br/>
<div>
<h3>Last update:</h3>
<div>Method: {{ lastUpdate.method }}</div>
<div>Path: {{ lastUpdate.path }}</div>
<div>Collection: {{ lastUpdate.collection }}</div>
<div>Id: {{ lastUpdate.itemId }}</div>
</div>
</div>
</body>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/3.5.2/superagent.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
collections: '',
lastUpdate: {
method: '-',
path: '-',
collection: '-',
itemId: '-'
}
}
});
const request = window.superagent;
request
.get(`http://${window.location.host}/api`)
.then(response => {
app.collections = response.body;
}).catch(error => {
console.log(error.message || error);
});
const webSocket = new WebSocket(`ws://${window.location.host}/ws`);
webSocket.onmessage = (evt) => {
app.lastUpdate = JSON.parse(evt.data);
};
webSocket.onopen = () => {
console.log('open');
};
webSocket.onclose = () => {
console.log('closed');
};
webSocket.onerror = (evt) => {
console.log(evt.data);
};
</script>
</html>