MediaBrowser / Emby

Emby Server is a personal media server with apps on just about every device.
https://emby.media
GNU General Public License v2.0
4.18k stars 810 forks source link

site.js determines the server address wrong #1524

Closed plawatsch closed 8 years ago

plawatsch commented 8 years ago

Hi,

after quite some debugging i found a nasty bug in the dashboard.

When determining the server address in "manual" mode there are some heuristics being run (in site.js around line 128):

    // Try to get the server address from the browser url
    // This will preserve protocol, hostname, port and subdirectory
    var urlLower = window.location.href.toLowerCase();
    var index = urlLower.indexOf('/web');
    if (index == -1) {
        index = urlLower.indexOf('/dashboard');
    }

    if (index != -1) {
        return urlLower.substring(0, index);
    }

Sadly this breaks if the hostname of the emby instance starts with "web". In my case I had a hostname like "webmail.xxx.yyy.zzz" and instead of correctly turning

https://webmail.xxx.yyy.zzz:someport/web into https://webmail.xxx.yyy.zzz:someport it actually ends up returning https:/

This obviously breaks quite a bit of stuff later on (lots of api requests going to https://emby/foo/bar etc).

I guess a fix could be to simply look for the last instance of "/web" or even better first split off https:// and then run the /web parse on the rest of the string.

I'd be happy to test potential fixes.

kind regards

psxlover commented 8 years ago

Or you could simply look for /web/ instead

michaeljbailey commented 8 years ago

You can just use the anchor element to do this. Check out https://gist.github.com/jlong/2428561.

For Emby, we can just do

var urlLower = window.location.href.toLowerCase(); // Example: http://webmail.foo.bar.com:4473/web/stuff
var anchor = document.createElement('a');
anchor.href = urlLower;

var url = parser.protocol + parser.host; // http://webmail.foo.bar.com:4473