-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
31 lines (30 loc) · 791 Bytes
/
Copy pathindex.html
File metadata and controls
31 lines (30 loc) · 791 Bytes
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
<!doctype html>
<html>
<head>
<title>Exevent</title>
</head>
<body>
<div>
<h1>Stream from server</h1>
<button onclick="startStreaming()">Start Streaming</button>
<main></main>
</div>
<script>
function startStreaming(e) {
const eventSource = new EventSource(
"http://localhost:4000/stream/text.txt",
);
eventSource.onmessage = (event) => {
const main = document.querySelector("main");
const line = document.createElement("p");
line.textContent = event.data;
main.appendChild(line);
};
eventSource.onerror = (error) => {
console.log("EventSource failed:", error);
eventSource.close();
};
}
</script>
</body>
</html>