luci-base: rpc.js: make base URL configurable
authorJo-Philipp Wich <jo@mein.io>
Fri, 5 Apr 2019 06:08:17 +0000 (08:08 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 13:36:24 +0000 (15:36 +0200)
Implement setters and getters for the base URL prefix used and also
implement a session ID getter while we're at it.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/rpc.js

index cc22d0aeb4f1f4bc7ad6c467611dbe2e33bc14da..36f5434d9c2f6966a3154d6c7592dad1ffeee703 100644 (file)
@@ -3,7 +3,8 @@
 var rpcRequestRegistry = {},
     rpcRequestBatch = null,
     rpcRequestID = 1,
-    rpcSessionID = L.env.sessionid || '00000000000000000000000000000000';
+    rpcSessionID = L.env.sessionid || '00000000000000000000000000000000',
+    rpcBaseURL = L.url('admin/ubus');
 
 return L.Class.extend({
        call: function(req, cbFn) {
@@ -25,7 +26,7 @@ return L.Class.extend({
                        q += '/%s.%s'.format(req.params[1], req.params[2]);
                }
 
-               return L.Request.post(L.url('admin/ubus') + q, req, {
+               return L.Request.post(rpcBaseURL + q, req, {
                        timeout: (L.env.rpctimeout || 5) * 1000,
                        credentials: true
                }).then(cb);
@@ -190,7 +191,19 @@ return L.Class.extend({
                }, this, this, options);
        },
 
+       getSessionID: function() {
+               return rpcSessionID;
+       },
+
        setSessionID: function(sid) {
                rpcSessionID = sid;
+       },
+
+       getBaseURL: function() {
+               return rpcBaseURL;
+       },
+
+       setBaseURL: function(url) {
+               rpcBaseURL = url;
        }
 });