[Bug With Fix] Webui.js Has Hard Coded, Absolute Url


Recommended Posts

I have a linux machine running the btsync web interface on http://localhost:8888. I have apache configured to proxy requests from https://myhost/btsync to http://localhost:8888. It works great except that webui.js constantly tries to access http://myhost/gui, which is incorrect. It should be trying to access http://myhost/btsync/gui. I've narrowed the problem down to a function in webui.js, line 468, which reads:


requestToken: function(c, B)
var a = this;
type: "POST",
url: guiBase + "token.html?t=" + Date.now(),
async: false
}).done(function( f )
var e = f.match(/>([^<]+)</);
if(e) {
a.TOKEN = e[e.length - 1]
The problem is that the value in "guiBase" is absolute. It's set to "/gui/". It is defined a little earlier in the file at line 431, which reads:
var urlBase = "";
var guiBase = urlBase + "/gui/";
var proxyBase = urlBase + "/proxy";
This essentially hard codes btsync to only work when it is running as the root of a host. However, I have other services running on http://myhost/ that I don't want btsync to conflict with.
To fix this, the values of urlBase, guiBase, and proxyBase can all be set relative paths (relative to .../gui/, which is where they are currently referenced from):
// removed urlBase because we are using relative references now
var guiBase = ""; // now a relative path to /gui from /gui
var proxyBase = "../proxy"; // now a relative path to /proxy from /gui

With that change, btsync works flawlessly at different url paths. Would you please incorporate that change?


In case you're curious, here's my apache configuration:


<Proxy http://localhost:8888*>

        Require all granted


<Location /btsync>

        ProxyPass http://localhost:8888

        ProxyPassReverse http://localhost:8888



Thank you,

-- Scott

Link to post
Share on other sites



Additionally, it appears that some of the redirects that do not involve java script are also absolute.


If btsync is mapped to http://myserver/btsync, then


Going to http://myserver/btsync should go to http://myserver/btsync/gui/, but instead it goes to http://myserver/gui/. The redirect sent from btsync is to "/gui/" rather than "gui/"


-- Scott

Link to post
Share on other sites
  • 4 weeks later...
  • 2 months later...
  • 1 month later...
  • 2 months later...

I've been fighting with this particular bug, and was at first led astray by other threads that made it seem like simple HTML rewriting would do the trick - no such luck in client-executed Javascript. I assume this is all compiled into the Linux executable, as I can't locate anything on disk to edit; I can only make these changes on-the-fly in my browser. If anyone knows a way I can make this change permanent, please let me know! [EDIT: Found a way via nginx subs_filter!]


This bug is especially offensive as it is going out of its way to create the bad behavior - doing nothing would have worked fine. Doubly-offensive in that it was reported eight months ago and never fixed despite how simple it is.


In the v2.0 webui.js I'm looking at, start at line 1113 and delete the following lines:

var urlBase = "";var guiBase = urlBase + "/gui/";var proxyBase = urlBase + "/proxy";

Yes, delete entirely. None of this should exist. guiBase is causing the bug, proxyBase is completely unused, and urlBase is only used for guiBase/proxyBase, which will shortly be unnecessary. Then delete the references to guiBase on lines 1136 and 1156 - they're unnecessary. They should now look like this:



url: "?" + params.join('&'),


url: "token.html?t=" + Date.now(),

That's it - removing code fixes this bug.


Here's my nginx configuration that rewrites the JavaScript on the fly:

    location /proxy/btsync/ {        proxy_pass http://nas:8888/gui/;        subs_filter_types text/javascript;        subs_filter "/gui/" "";    }
Link to post
Share on other sites


This topic is now archived and is closed to further replies.