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

Server Sent Events are not working in a nodejs/express app #3765

Closed
thunder7553 opened this issue Sep 30, 2020 · 2 comments · Fixed by #3758
Closed

Server Sent Events are not working in a nodejs/express app #3765

thunder7553 opened this issue Sep 30, 2020 · 2 comments · Fixed by #3758
Labels
bug 🐞 Something isn't working
Milestone

Comments

@thunder7553
Copy link

With Caddy 2.2.0, the responses from the server are only sent unbuffered when the content type is text/event-stream. NodeJS express sends out a Content Type of text/event-stream; charset=utf-8.

I am not so deep in the specs to know if caddy or express is at fault. I would expect caddy to gracefully accept any arguments to the content-type: text/event-stream.

Workaround 1

It is possible to get it working with express (by not using express, but the underlaying nodejs function calls directly).

    res.writeHead(200, {
      'Content-Type': 'text/event-stream',
      'Cache-Control': 'no-cache',
      'X-Accel-Buffering': 'no',
      'Transfer-Encoding': 'chunked',
    });

Workaraound 2

Setting flush_interval to -1 in the Caddyfile works as well.

@francislavoie
Copy link
Member

I think #3758 is likely the fix you will need

@cmfcmf
Copy link
Contributor

cmfcmf commented Sep 30, 2020

I think #3758 is likely the fix you will need

Yes, indeed. I stumbled across this issue when using Next.js, which adds the same charset parameter to its event streams. A temporary 'fix' is to set flush_interval to -1:

reverse_proxy {
	... 
	flush_interval -1
}

Edit: Just noticed that the workaround was already mentioned above 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
3 participants