From 2ceb6fb4a67c75067930f5ecfeb63b3acd98526c Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Mon, 22 Jul 2024 11:30:09 +1000 Subject: [PATCH] Dev UI Base path fix in case of non-application root set to dev* Signed-off-by: Phillip Kruger --- .../src/main/resources/dev-ui/controller/jsonrpc.js | 6 ++---- .../resources/dev-ui/controller/router-controller.js | 10 +++++++--- .../src/main/resources/dev-ui/qwc/qwc-external-page.js | 4 +--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/jsonrpc.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/jsonrpc.js index bfd86942f2612..757518fe3d0a3 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/jsonrpc.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/jsonrpc.js @@ -125,9 +125,7 @@ export class JsonRpc { } else { JsonRpc.serverUri = "ws:"; } - var currentPath = window.location.pathname; - currentPath = currentPath.substring(0, currentPath.indexOf('/dev')) + "/dev-ui"; - JsonRpc.serverUri += "//" + window.location.host + currentPath + "/json-rpc-ws"; + JsonRpc.serverUri += "//" + window.location.host + RouterController.getBasePath() + "/json-rpc-ws"; JsonRpc.connect(); } @@ -345,4 +343,4 @@ export class JsonRpc { JsonRpc.dispatchMessageLogEntry(Level.Info, MessageDirection.Down, jsonrpcpayload); } } -} \ No newline at end of file +} diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js index 3fd5f879c6e6d..edaac4b75aa26 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js @@ -134,13 +134,17 @@ export class RouterController { return null; } - getBasePath(){ + static getBasePath(){ var base = window.location.pathname; - return base.substring(0, base.indexOf('/dev')) + "/dev-ui"; + if(base.endsWith("/dev-ui")){ + return base.substring(0, base.lastIndexOf('/dev-ui')) + "/dev-ui"; + }else{ + return base.substring(0, base.lastIndexOf('/dev-ui/')) + "/dev-ui"; + } } getPageUrlFor(page){ - return this.getBasePath() + '/' + page.id; + return RouterController.getBasePath() + '/' + page.id; } isExistingPath(path) { diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-external-page.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-external-page.js index 5bf4e2c3a1218..7d533dbe56849 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-external-page.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-external-page.js @@ -108,8 +108,6 @@ export class QwcExternalPage extends observeState(LitElement) { height='100%'> `; } else { - let currentPath = window.location.pathname; - currentPath = currentPath.substring(0, currentPath.indexOf('/dev')); return html`
@@ -130,4 +128,4 @@ export class QwcExternalPage extends observeState(LitElement) { window.open(this._externalUrl, '_blank').focus(); } } -customElements.define('qwc-external-page', QwcExternalPage); \ No newline at end of file +customElements.define('qwc-external-page', QwcExternalPage);