-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
29 lines (26 loc) · 880 Bytes
/
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSE Stack Example</title>
</head>
<body>
<h1>Messages</h1>
<ul id="messages"></ul>
<script>
// Use EventSource to listen to SSE events from the server
const eventSource = new EventSource('http://localhost:3000/sse');
eventSource.onmessage = function(event) {
const message = JSON.parse(event.data);
const messageList = document.getElementById('messages');
const newItem = document.createElement('li');
newItem.textContent = message.text;
messageList.appendChild(newItem);
};
eventSource.onerror = function(event) {
console.error('EventSource failed:', event);
};
</script>
</body>
</html>