From 93f9a66fc7b04af7457175bb5e38e9704313ebc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr>
Date: Tue, 21 Sep 2021 17:37:46 +0200
Subject: [PATCH] Add getClientSettingsUrl (bug base href)

---
 client/src/app/app-init.ts                  | 12 +++++++++++-
 client/src/environments/environment.prod.ts |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/client/src/app/app-init.ts b/client/src/app/app-init.ts
index 6b9241ee..c1e25371 100644
--- a/client/src/app/app-init.ts
+++ b/client/src/app/app-init.ts
@@ -11,7 +11,7 @@ import { environment } from 'src/environments/environment';
 
 function appInit(http: HttpClient, appConfigService: AppConfigService, keycloak: KeycloakService, store: Store<{ }>) {
     return () => {
-        return http.get(`${environment.apiUrl}/client-settings`)
+        return http.get(getClientSettingsUrl())
             .toPromise()
             .then(data => {
                 Object.assign(appConfigService, data);
@@ -24,6 +24,16 @@ function appInit(http: HttpClient, appConfigService: AppConfigService, keycloak:
     }
 }
 
+function getClientSettingsUrl() {
+    let url: string;
+    if (environment.production) {
+        url = `${document.getElementsByTagName('base')[0].getAttribute('href')}${environment.apiUrl}/client-settings`;
+    } else {
+        url = environment.apiUrl;
+    }
+    return url;
+}
+
 export const appInitializer = {
     provide: APP_INITIALIZER,
     useFactory: appInit,
diff --git a/client/src/environments/environment.prod.ts b/client/src/environments/environment.prod.ts
index 5506fedd..f60eda9a 100644
--- a/client/src/environments/environment.prod.ts
+++ b/client/src/environments/environment.prod.ts
@@ -1,4 +1,4 @@
 export const environment = {
     production: true,
-    apiUrl: "/server"
+    apiUrl: "server"
 };
-- 
GitLab