-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.astro
78 lines (62 loc) · 1.5 KB
/
index.astro
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
74
75
76
77
78
---
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Astro</title>
</head>
<body>
<h1>Astro Sidecar(s)</h1>
<h2>Data from the mocking server (http://localhost:5001)</h2>
<pre id="ms">Awaiting data…</pre>
<hr />
<h2>Data from the WebSocket server (ws://localhost:5002)</h2>
<pre id="ws">Awaiting message…</pre>
</body>
</html>
<script>
/* === MOCKING === */
import { MOCK_API_DEV_URL } from '../../consts.js';
async function fetchFromREST() {
const mData = await fetch(MOCK_API_DEV_URL)
.then((r) => r.json())
.catch((e) => {
console.error(e);
return { error: true };
});
console.log({ mData });
const msResult = document.querySelector('pre#ms')!;
msResult.innerHTML = JSON.stringify(mData);
}
setInterval(() => {
fetchFromREST();
}, 3000);
</script>
<script>
/* === WEB SOCKET === */
import { io } from 'socket.io-client';
import { WEB_SOCKET_DEV_URL } from '../../consts.js';
let ioClient: ReturnType<typeof io> | undefined;
try {
ioClient = io(WEB_SOCKET_DEV_URL);
} catch (e) {
console.error(e);
}
if (ioClient) {
ioClient.on('seq-num', (msg) => {
console.info(msg);
const wsResult = document.querySelector('pre#ws')!;
wsResult.innerHTML = `seq-num: ${JSON.stringify(msg)}`;
});
}
</script>
<style>
body {
padding: 10vw;
background-color: midnightblue;
color: white;
font-family: system-ui;
}
</style>