bittorrent / webui

BSD 3-Clause "New" or "Revised" License
114 stars 32 forks source link

Bug in determination of urlBase (for Reverse Proxy support for example) #1

Open ghost opened 13 years ago

ghost commented 13 years ago

Hi,

Since I'm new to git (hub) I don't want to mess things up by modifying anything myself. I do have a request/issue though:

I've setup a reverse proxy in IIS 7.5 using ARR and the IIS Rewrite Module. It works like this: http://mydomain.com/utorrent/ -> http://127.0.0.1:PORT/gui/

The uTorrent WebUI (in webui.js) creates a urlBase variable using the position of "/gui" in window.location.pathname. Using my external address, the window.location.pathname does not contain "/gui". Hence urlBase will contain an empty string.

I would like urlBase to contain "/utorrent" so that the guiBase variable will contain "/utorrent/gui/" and the reverse proxy will work correctly :).

Would it be possible to substitute the creation of urlBase by the following (ugly) code?

// Determine urlBase (use the entire pathname if "/gui" is not found, use everything before "/gui" otherwise) var urlBase = (window.location.pathname.indexOf("/gui") == -1) ? window.location.pathname : window.location.pathname.substr(0, window.location.pathname.indexOf("/gui"));

// Remove any trailing / characters while (urlBase[urlBase.length - 1] == "/") { urlBase = urlBase.substr(0, urlBase.length - 1); }

I've tested this on my server, and it seems to work pretty well :).

asze commented 13 years ago
var urlBase = window.location.pathname.split("/gui", 1)[0].replace(/\/+$/, "");

How does this snippet instead work for you?

ghost commented 13 years ago

Hi asze,

The snippet seems to work correctly. I've successfully tested it using the following 3 URLs:

Will this be included in the webui release?