Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix path based proxying issues (#1821)

Wouter Bornaaa6b849050b
diff --git a/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts b/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts
index a839a9270..40eeb47e1 100644
--- a/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts
+++ b/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts
@@ -30,6 +30,7 @@ import {
DefaultColor5,
DefaultColor6,
DefaultColor8,
+ manager,
Util,
} from "@openremote/core";
import { i18next } from "@openremote/or-translate";
@@ -39,8 +40,6 @@ import {when} from 'lit/directives/when.js';
import ISO6391 from 'iso-639-1';
import {DefaultHeaderMainMenu, DefaultHeaderSecondaryMenu} from "../../../index";
-declare const MANAGER_URL: string
-
@customElement("or-conf-realm-card")
export class OrConfRealmCard extends LitElement {
@@ -269,7 +268,7 @@ export class OrConfRealmCard extends LitElement {
render() {
const colors = this._getColors();
const app = this;
- const managerUrl = (MANAGER_URL || "");
+ const managerUrl = (manager.managerUrl ?? "");
// On an empty search; return the common language as set in DEFAULT_LANGUAGES
// If searching, compare strings using lowercase. (with no maximum)
diff --git a/ui/app/manager/src/index.ts b/ui/app/manager/src/index.ts
index 63940721c..ca3cb7c48 100644
--- a/ui/app/manager/src/index.ts
+++ b/ui/app/manager/src/index.ts
@@ -114,7 +114,9 @@ export const DefaultRealmConfig: RealmAppConfig = {
};
// Try and load the app config from JSON and if anything is found amalgamate it with default
-const configURL = (MANAGER_URL ?? "") + "/api/master/configuration/manager";
+const managerURL = MANAGER_URL || window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "")
+ + window.location.pathname.replace(/\/[^/]+\/?$/, '');
+const configURL = managerURL + "/api/master/configuration/manager";
fetch(configURL).then<ManagerAppConfig>(async (result) => {
let appConfig: ManagerAppConfig;
diff --git a/ui/app/manager/src/pages/page-configuration.ts b/ui/app/manager/src/pages/page-configuration.ts
index 37884dedd..b5f93aebf 100644
--- a/ui/app/manager/src/pages/page-configuration.ts
+++ b/ui/app/manager/src/pages/page-configuration.ts
@@ -37,7 +37,6 @@ import {OrConfPanel} from "../components/configuration/or-conf-panel";
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
import {DefaultHeaderMainMenu, DefaultHeaderSecondaryMenu, DefaultRealmConfig} from "../index";
-declare const MANAGER_URL: string | undefined;
declare const APP_VERSION: string;
export function pageConfigurationProvider(store: Store<AppStateKeyed>): PageProvider<AppStateKeyed> {
@@ -367,7 +366,7 @@ export class PageConfiguration extends Page<AppStateKeyed> {
this.loading = false;
this.managerConfigurationChanged = false;
this.mapConfigChanged = false;
- const configURL = (MANAGER_URL ?? "") + "/api/master/configuration/manager";
+ const configURL = (manager.managerUrl ?? "") + "/api/master/configuration/manager";
fetch(configURL, {cache: "reload"})
window.location.reload();
})
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index 4f69f6022..08801704c 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -209,11 +209,11 @@ export class Manager implements EventProviderFactory {
}
get managerUrl() {
- return this._config.managerUrl;
+ return this._config?.managerUrl;
}
get keycloakUrl() {
- return this._config.keycloakUrl;
+ return this._config?.keycloakUrl;
}
get isError() {
@@ -655,7 +655,7 @@ export class Manager implements EventProviderFactory {
if (this._config.loadIcons) {
IconSets.addIconSet(
"mdi",
- createMdiIconSet(manager.config.managerUrl!)
+ createMdiIconSet(manager.managerUrl!)
);
IconSets.addIconSet(
"or",
@@ -666,7 +666,7 @@ export class Manager implements EventProviderFactory {
protected async getConsoleAppConfig(): Promise<boolean> {
try {
- const response = await fetch(manager.config.managerUrl + "/consoleappconfig/" + manager.displayRealm + ".json");
+ const response = await fetch((manager.managerUrl ?? "") + "/consoleappconfig/" + manager.displayRealm + ".json");
this._consoleAppConfig = await response.json() as ConsoleAppConfig;
return true;
} catch (e) {
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.ts
index d5765f6c6..42a5106f5 100644
--- a/ui/component/or-app/src/index.ts
+++ b/ui/component/or-app/src/index.ts
@@ -372,15 +372,15 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
if (!this._config.logo) {
this._config.logo = DefaultLogo;
}else{
- this._config.logo = (MANAGER_URL || "")+this._config.logo
+ this._config.logo = (manager.managerUrl ?? "") + this._config.logo
}
if (!this._config.logoMobile) {
this._config.logoMobile = DefaultMobileLogo;
}else{
- this._config.logoMobile = (MANAGER_URL || "")+this._config.logoMobile
+ this._config.logoMobile = (manager.managerUrl ?? "") + this._config.logoMobile
}
- const favIcon = this._config && this._config.favicon ? (MANAGER_URL || "")+this._config.favicon : DefaultFavIcon;
+ const favIcon = this._config && this._config.favicon ? (manager.managerUrl || "") + this._config.favicon : DefaultFavIcon;
let link = document.querySelector("link[rel~='icon']") as HTMLLinkElement;
diff --git a/ui/component/or-survey/src/index.ts b/ui/component/or-survey/src/index.ts
index 23f795218..08fe3a56c 100644
--- a/ui/component/or-survey/src/index.ts
+++ b/ui/component/or-survey/src/index.ts
@@ -12,7 +12,6 @@ import filter from "lodash-es/filter";
import "@openremote/or-translate";
const moment = momentImported;
-declare var MANAGER_URL: string;
export interface OrComputeGridEventDetail {
}
@@ -291,7 +290,7 @@ class OrSurvey extends LitElement {
localStorage.setItem('survey'+this.survey.id, "set");
const xhttp = new XMLHttpRequest();
- const url = manager.config.managerUrl ? manager.config.managerUrl+"/rest/survey/" : window.location.origin+"/rest/survey/";
+ const url = manager.managerUrl ? manager.managerUrl+"/rest/survey/" : window.location.origin+"/rest/survey/";
xhttp.open("POST", url + this.survey.id, true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(JSON.stringify(this.surveyAnswers));
diff --git a/ui/util/webpack.util.js b/ui/util/webpack.util.js
index 8360e5026..782dfa228 100644
--- a/ui/util/webpack.util.js
+++ b/ui/util/webpack.util.js
@@ -66,7 +66,7 @@ function getAppConfig(mode, isDevServer, dirname, managerUrl, keycloakUrl, port)
},
output: {
path: dirname + "/dist",
- publicPath: "/" + dirname.split(path.sep).slice(-1)[0] + "/",
+ publicPath: isDevServer ? "/" + dirname.split(path.sep).slice(-1)[0] + "/" : "./",
filename: production ? "[name].[contenthash].js" : "[name].js"
},
module: {...getStandardModuleRules()},