Skip to content

Instantly share code, notes, and snippets.

@lifez
Created September 20, 2019 07:53
Show Gist options
  • Save lifez/1e3b3a3871b698ee3ba370561ae5fad6 to your computer and use it in GitHub Desktop.
Save lifez/1e3b3a3871b698ee3ba370561ae5fad6 to your computer and use it in GitHub Desktop.
<html>
<body>
<div id="messages">
</div>
<script>
let source = new EventSource('http://localhost:3000')
source.onmessage = event => {
data = JSON.parse(event.data)
document.getElementById('messages').insertAdjacentHTML('beforeend', `<p>${data.message}</p>`)
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment