Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with Server-Sent Events #17

Closed
pallymore opened this issue Jun 18, 2014 · 6 comments
Closed

Does not work with Server-Sent Events #17

pallymore opened this issue Jun 18, 2014 · 6 comments
Assignees

Comments

@pallymore
Copy link

So I'm working on a small application which uses Server-Sent Events...everything works perfectly in my local environment, but the server refuses to push out any messages when the app runs on heroku.

I spent quite a few hours trying to debug this.. Then I found out it's because I'm using compression middleware in production environment. everything works again as soon as I remove it.

I'm using the basic SSE implementation, not using any third party library for that. You should be able to reproduce this issue by adding this middleware to any expressjs + SSE code examples. (like this one: https://github.com/TravelingTechGuy/express-eventsource)

I'm fairly new to expressjs. I'd be great if this can be solved (or if anyone can provide a workaround solution).

Thanks!

@dougwilson
Copy link
Contributor

You need to call res.flush() after you write your event if you want it actually flushed out to the client. For your demo there, you want to add res.flush() after line 60: https://github.com/TravelingTechGuy/express-eventsource/blob/master/models/eventsource.js#L60 and it works fine.

@pallymore
Copy link
Author

ah...thanks! :)

@pallymore
Copy link
Author

Actually...it seems there's no such method :/
(as of ExpressJS 4)
http://nodejs.org/api/http.html#http_response_write_chunk_encoding

@dougwilson
Copy link
Contributor

res.flush is added by this library: https://github.com/expressjs/compression/blob/master/index.js#L161

I do need to add that to the readme, it seems.

@pallymore
Copy link
Author

thanks again! works perfectly now :)

@dougwilson
Copy link
Contributor

Awesome! I need to add this information to the README, haha. I'm going to keep this open until I do :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants