Skip to content

Instantly share code, notes, and snippets.

@yurifrl
Created March 2, 2017 03:22
Show Gist options
  • Save yurifrl/64cc2a1a77bfc2659c5a6c6edf8eb127 to your computer and use it in GitHub Desktop.
Save yurifrl/64cc2a1a77bfc2659c5a6c6edf8eb127 to your computer and use it in GitHub Desktop.
tail -f to the web-browser
# 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