Event-heartbeat wrong url in case of port-forwarding


Using ServerEvents in Javascript, i get some errors if i expose my ServerEvents Server to the internet, using a portforwarding in the router that forwards outside port 8180 to client port 80.

The url is temporary including the 8180 port. When firing up ServerEvents, i get these errors in Networktraffic:

event-heartbeat uses the wrong URL, where event-stream is using the right url. Is this something configurable?

The url’s are showing up as:

Connection is initialized in a normal way afaik:

$(document).ready(function () {
    eventSource = new EventSource('/event-stream?channel=home,events&t=' + new Date().getTime());
    $(eventSource).handleServerEvents({ ....

Thanks again,


ServiceStack uses the incoming Request URL to create its Absolute URL links which can be overridden for all resolved links by either hard-coding the BaseUrl with:

SetConfig(new HostConfig {
    WebHostUrl = "http://domain.goes.here:8180"

Or by overriding GetBaseUrl() or ResolveAbsoluteUrl() in your AppHost.

Or if only want to change the urls returned in Server Events:

Plugins.Add(new ServerEventsFeature {
    OnConnect = (sub, connectArgs) => {
        connectArgs["heartbeatUrl"] = connectArgs["heartbeatUrl"]
        connectArgs["unRegisterUrl"] = connectArgs["unRegisterUrl"]
        connectArgs["updateSubscriberUrl"] = connectArgs["updateSubscriberUrl"]

Okay, i do this now:

public override string GetBaseUrl(ServiceStack.Web.IRequest httpReq)
		/// Url's are not parsed correctly with possible different port then ServiceStack normal BaseUrl
		var userHostName = ((System.Net.HttpListenerRequest)httpReq.OriginalRequest).UserHostName;
		var result = base.GetBaseUrl(httpReq);

		if (result.Contains("https"))
			return "https://{0}".Fmt(userHostName);
			return "http://{0}".Fmt(userHostName);

Still, i would say something is off; all requests will work fine, except the ServerEvents Feature, also; Auth HtmlRedirect etc… url’s are ‘off’. Maybe i’m the one doing something weird here, but in my experience, more it systems wil forward ports to other ports then te base port in the website.


ServiceStack is only able to generate the Absolute URL from the incoming request url, if you’re using a Reverse proxy then the proxy normally does the url rewriting into the external url (e.g. links in HTML pages), but it’s likely it’s not modifying urls returned in JSON responses.