notes/sandbox/vue_sse/vue_sse_front/public/index.js
2023-04-22 00:41:54 -07:00

11 lines
335 B
JavaScript

const sse = new EventSource("http://localhost:8080/stream")
const streamSection = document.querySelector('.stream-section')
sse.onmessage = (e) => {
const node = document.createElement('li')
node.textContent = e.data
streamSection.appendChild(node)
}
// stops stream after 30 seconds
setTimeout(() => sse.close(), 30000)