tpeczek/Lib.AspNetCore.ServerSentEvents

InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: 'Server-Sent Events'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.

Closed this issue · 3 comments

No matter what I try, I get the following exception when going to the stream, this also happens with the demo app.

InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: 'Server-Sent Events'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.

Hi @rogierhofboer,

The most common cases when I've seen this error is either a request made to the wrong endpoint or a request made to the correct endpoint but the media type doesn't suggest a Server-Sent Events request. Can you share your request sample?

Hi @tpeczek,

Thanks for your prompt response and for creating this library!

I was just browsing to the endpoint.
With an implementation I used years ago in golang, this was possible and the events just showed up in the browser.
So I expected this to work. I am not sure if with the current specifications this would still be possible / allowed.
It is however quite handy for debugging.

It works when using plain Javascript to connect :)

Biggest challenge was getting it working through an nginx reverse proxy...
Only adding the headers suggested here https://tpeczek.github.io/Lib.AspNetCore.ServerSentEvents/articles/advanced.html did not work for me. Adding the following in the nginx for the location did the trick:

proxy_http_version 1.1;
proxy_set_header Connection '';
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;

I am not sure (yet) what is exactly needed both on nginx and on the .NET WebApi side, maybe it also possible with less extra extra settings.

In case of most modern browser, just navigating will make a request with a text/plain or text/html as accepted mime types, so SSE endpoint shouldn't respond to that.

When it comes to nginx (or other proxies) things might be complicated and depend on other configuration already in place, the documentation only covers the most typical settings and ensures that .NET layer doesn't buffer.