Created
March 2, 2017 03:22
-
-
Save yurifrl/64cc2a1a77bfc2659c5a6c6edf8eb127 to your computer and use it in GitHub Desktop.
tail -f to the web-browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://medium.com/@joewalnes/tail-f-to-the-web-browser-b933d9056cc#.nzwlj0wp6 | |
# Server | |
$ (echo -e ‘HTTP/1.1 200 OK\nAccess-Control-Allow-Origin: *\nContent-type: text/event-stream\n’ && tail -f /path/to/some/file | sed -u -e ‘s/^/data: /;s/$/\n/’) | nc -l 1234 | |
# Browser | |
new EventSource("http://host:1234/").onmessage = function(e) { | |
console.log(e.data); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment