rexxars / sse-channel

Server-Sent Events "channel" where all messages are broadcasted to all connected clients, history is maintained automatically and server attempts to keep clients alive by sending "keep-alive" packets automatically.
MIT License
111 stars 11 forks source link

Issues with Express #4

Closed fabien closed 9 years ago

fabien commented 9 years ago

I've trying to get sse-channel to work in an existing Express app, and it appears to work from my specs as well as plain curl usage. However, none of the browsers I tried (Chrome, Safari, FF) seem to work, after successfully connecting (open).

Something really strange is happening - the request stays pending in Chrome's network inspector, and then suddenly, after many minutes (up to 6 or so) some events come through. Then it stops again.

Is there anything I can check to resolve this issue? The response appears to be identical to your example and other sse scripts on the net.

fabien commented 9 years ago

Found it - I was using compress middleware: https://github.com/expressjs/compression (see the note about Server-Sent Events)

rexxars commented 9 years ago

Thanks for reporting and finding the solution, I'll add a note about this in the README.

rexxars commented 9 years ago

Also, I might add an option to explicitly call flush after each write. That would probably be a Good Thing(tm).

fabien commented 9 years ago

Both would be great to have, yeah! Thanks!

rexxars commented 9 years ago

Solved in 4f00f4f and released as 1.0.6. I didn't see any reason to use an option for this - it seemed like the reasonable thing to do, so it simply checks if the flush method exists on the response and calls it after a write. Thanks again for reporting.