We found a problem when using ServerSide Events and nginx to access out host.
We have a c# service running under
Our SSE endpoint is at
Our nginx configuration has a section for the SSE endpoint. It will make this translation
outside: https://our.full.domain/sse → inside: http://localhost:5172/service/sse
This is the full nginx configuration section
location /sse { proxy_pass http://localhost:5172/service/sse; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ''; proxy_buffering off; proxy_cache off; chunked_transfer_encoding off; }
The problem is:
We’re using nginx for security and for its ability to provide SSL.
When the subscription event happens, the c# logic for ServerEventsFeature seems to run this code
subscription.ConnectArgs = new Dictionary<string, string>(subscription.ConnectArgs) {
{“id”, subscriptionId },
{“unRegisterUrl”, unRegisterUrl},
{“heartbeatUrl”, heartbeatUrl},
{“updateSubscriberUrl”, req.ResolveAbsoluteUrl(“~/”.CombineWith(feature.SubscribersPath, subscriptionId)) },
{“heartbeatIntervalMs”, ((long)feature.HeartbeatInterval.TotalMilliseconds).ToString(CultureInfo.InvariantCulture) },
{“idleTimeoutMs”, ((long)feature.IdleTimeout.TotalMilliseconds).ToString(CultureInfo.InvariantCulture)}
};
At this point, the updateSubscriberUrl endpoint is calculated like this
{“updateSubscriberUrl”, req.ResolveAbsoluteUrl(“~/”.CombineWith(feature.SubscribersPath, subscriptionId)) },
Which causes the URL to be formatted as:
Instead of
Due to this, the nginx server receives a request on
/service/sse
which results in an error on our the typescript client app
And sometimes we get failed URLs in the browser
Fetch failed loading: POST “https://our.full.domain/sse/json/reply/UpdateEventSubscriber”.
Question: Is there a way we can override this behavior?
Is there a way we can setup the url as we do for the other events?
Why is this url being treated in a different way, rather than having a property named UpdateSubscriberUrl, like we have for the other events?
We attempted to override using
var sseBasePath = “/sse”;
se.StreamPath = $“{sseBasePath}/event-stream”;
se.HeartbeatPath = $“{sseBasePath}/event-heartbeat”;
se.SubscribersPath = $“{sseBasePath}/event-subscribers”;
se.UnRegisterPath = $“{sseBasePath}/event-unregister”;
But that did not work either.
Any help will be greatly appreciated.