Cleaned up urlBase() readability.
Updated unit tests, and added a test for the app context in the URL.

Change-Id: I110b62ff8366a503c3309df0f26a7dd213ae0c5f
diff --git a/web/gui/src/main/webapp/app/fw/remote/urlfn.js b/web/gui/src/main/webapp/app/fw/remote/urlfn.js
index 03ae09e..bf142d4 100644
--- a/web/gui/src/main/webapp/app/fw/remote/urlfn.js
+++ b/web/gui/src/main/webapp/app/fw/remote/urlfn.js
@@ -34,19 +34,20 @@
             }
 
             function urlBase(protocol, port, host) {
-                // A little bit of funky here. It is possible that ONOS sits behind a proxy
-                // and has an app prefix, e.g. http://host:port/my/app/onos/ui... This bit
-                // of regex grabs everything after the host:port and before the uiContext
-                // (/onos/ui/) and uses that as an app prefix by inserting it back into
-                // the WS URL, if no prefix, then no insert.
-                var prefix = ""
-                if ($loc.absUrl) {
-                    var p = $loc.absUrl().match(".*//[^/]+/(.+)"+uiContext);
-                    prefix = p ? '/' + p[1] : '';
-                }
+                // A little bit of funky here. It is possible that ONOS sits
+                // behind a proxy and has an app prefix, e.g.
+                //      http://host:port/my/app/onos/ui...
+                // This bit of regex grabs everything after the host:port and
+                // before the uiContext (/onos/ui/) and uses that as an app
+                // prefix by inserting it back into the WS URL.
+                // If no prefix, then no insert.
+
+                var match = $loc.absUrl().match('.*//[^/]+/(.+)' + uiContext),
+                    appPrefix = match ? '/' + match[1] : '';
 
                 return matchSecure(protocol) + '://' +
-                    (host || $loc.host()) + ':' + (port || $loc.port()) + prefix;
+                    (host || $loc.host()) + ':' +
+                    (port || $loc.port()) + appPrefix;
             }
 
             function httpPrefix(suffix) {