luci-base: use native ubus HTTP gateway if available
authorJo-Philipp Wich <jo@mein.io>
Mon, 8 Jul 2019 15:39:24 +0000 (17:39 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 8 Jul 2019 15:39:24 +0000 (17:39 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 93ecbac15f1c16c05861c2dbadce7addfe34ea38..1bb4673b0af54efa88c8d66179d1809437b53181 100644 (file)
                        Promise.all([
                                domReady,
                                this.require('ui'),
-                               this.require('form')
+                               this.require('rpc'),
+                               this.require('form'),
+                               Request.get('/ubus/').catch(function() { return { status: 0 } })
                        ]).then(this.setupDOM.bind(this)).catch(this.error);
 
                        originalCBIInit = window.cbi_init;
                },
 
                /* DOM setup */
-               setupDOM: function(ev) {
+               setupDOM: function(res) {
+                       var domEv = res[0],
+                           uiClass = res[1],
+                           rpcClass = res[2],
+                           formClass = res[3],
+                           ubusReply = res[4];
+
+                       if (ubusReply.status == 400)
+                               rpcClass.setBaseURL('/ubus/');
+
                        Request.addInterceptor(function(res) {
                                if (res.status != 403 || res.headers.get('X-LuCI-Login-Required') != 'yes')
                                        return;