diff --git a/web/src/app/app.component.ts b/web/src/app/app.component.ts index d347aa0..d27b5ef 100644 --- a/web/src/app/app.component.ts +++ b/web/src/app/app.component.ts @@ -22,7 +22,6 @@ export class AppComponent implements OnDestroy { this.auth.user$.pipe(takeUntil(this.unsubscribe$)).subscribe((user) => { this.isLoggedIn = user !== null && user !== undefined; - console.warn("isLoggedIn"); }); this.sidebar.visible$ diff --git a/web/src/app/app.module.ts b/web/src/app/app.module.ts index 73100e6..8945836 100644 --- a/web/src/app/app.module.ts +++ b/web/src/app/app.module.ts @@ -22,6 +22,7 @@ import { SidebarComponent } from "./components/sidebar/sidebar.component"; import { ErrorHandlingService } from "src/app/service/error-handling.service"; import { HomeComponent } from "./components/home/home.component"; import { RedirectComponent } from "./components/redirect/redirect.component"; +import { SettingsService } from "src/app/service/settings.service"; if (environment.production) { Logger.enableProductionMode(); @@ -33,6 +34,20 @@ export function HttpLoaderFactory(http: HttpClient) { return new TranslateHttpLoader(http); } +export function appInitializerFactory( + keycloak: KeycloakService, + settings: SettingsService, +): () => Promise { + return (): Promise => + new Promise((resolve, reject) => { + settings + .loadSettings() + .then(() => initializeKeycloak(keycloak, settings)) + .then(() => resolve()) + .catch((error) => reject(error)); + }); +} + @NgModule({ declarations: [ AppComponent, @@ -71,9 +86,9 @@ export function HttpLoaderFactory(http: HttpClient) { KeycloakService, { provide: APP_INITIALIZER, - useFactory: initializeKeycloak, + useFactory: appInitializerFactory, multi: true, - deps: [KeycloakService], + deps: [KeycloakService, SettingsService], }, { provide: ErrorHandler, diff --git a/web/src/app/components/footer/footer.component.ts b/web/src/app/components/footer/footer.component.ts index b922851..b44bb0c 100644 --- a/web/src/app/components/footer/footer.component.ts +++ b/web/src/app/components/footer/footer.component.ts @@ -10,14 +10,14 @@ export class FooterComponent { constructor(private settings: SettingsService) {} get termsUrl(): string { - return this.settings.getTermsURL(); + return this.settings.settings.termsUrl; } get privacyUrl(): string { - return this.settings.getPrivacyURL(); + return this.settings.settings.privacyURL; } get imprintUrl(): string { - return this.settings.getImprintURL(); + return this.settings.settings.imprintURL; } } diff --git a/web/src/app/components/home/home.component.ts b/web/src/app/components/home/home.component.ts index bc54070..d5715b1 100644 --- a/web/src/app/components/home/home.component.ts +++ b/web/src/app/components/home/home.component.ts @@ -8,6 +8,7 @@ import { KeycloakService } from "keycloak-angular"; }) export class HomeComponent { constructor(private keycloak: KeycloakService) { + console.warn("home", this.keycloak.isLoggedIn()); if (!this.keycloak.isLoggedIn()) { this.keycloak.login().then(() => {}); } diff --git a/web/src/app/components/redirect/redirect.component.html b/web/src/app/components/redirect/redirect.component.html index 2b99b43..52e15e4 100644 --- a/web/src/app/components/redirect/redirect.component.html +++ b/web/src/app/components/redirect/redirect.component.html @@ -1,12 +1,12 @@
+ style="background-image: url({{settings.loadingScreen.background}})">
diff --git a/web/src/app/components/redirect/redirect.component.ts b/web/src/app/components/redirect/redirect.component.ts index 280327c..6b05f51 100644 --- a/web/src/app/components/redirect/redirect.component.ts +++ b/web/src/app/components/redirect/redirect.component.ts @@ -4,6 +4,8 @@ import { Router } from "@angular/router"; import { HttpClient } from "@angular/common/http"; import { environment } from "src/environments/environment"; import { ShortUrlDto } from "src/app/model/entities/short-url"; +import { SettingsService } from "src/app/service/settings.service"; +import { AppSettings } from "src/app/model/config/app-settings"; @Component({ selector: "app-redirect", @@ -14,10 +16,13 @@ export class RedirectComponent implements OnInit { defaultSecs = 5; secs = -1; + settings: AppSettings = this.settingsService.settings; + constructor( private sidebar: SidebarService, private router: Router, private http: HttpClient, + private settingsService: SettingsService, ) { this.sidebar.hide(); } @@ -37,7 +42,7 @@ export class RedirectComponent implements OnInit { } this.http - .get(`${environment.api.url}/find/${shortUrl}`) + .get(`${this.settings.api.url}/find/${shortUrl}`) .subscribe(async (response) => { if (!response) { await this.router.navigate(["/404"]); @@ -45,7 +50,7 @@ export class RedirectComponent implements OnInit { } if (!response.loadingScreen) { - window.location.href = `${environment.api.url}/redirect/${shortUrl}`; + window.location.href = `${this.settings.api.url}/redirect/${shortUrl}`; return; } @@ -54,7 +59,7 @@ export class RedirectComponent implements OnInit { this.secs--; if (this.secs === 0) { - window.location.href = `${environment.api.url}/redirect/${shortUrl}`; + window.location.href = `${this.settings.api.url}/redirect/${shortUrl}`; } }, 1000); }); diff --git a/web/src/app/core/init-keycloak.ts b/web/src/app/core/init-keycloak.ts index 482c9cd..48785ff 100644 --- a/web/src/app/core/init-keycloak.ts +++ b/web/src/app/core/init-keycloak.ts @@ -1,17 +1,20 @@ import { KeycloakService } from "keycloak-angular"; import { environment } from "src/environments/environment"; +import { SettingsService } from "src/app/service/settings.service"; -export function initializeKeycloak(keycloak: KeycloakService) { - return () => - keycloak.init({ - config: { - url: environment.auth.url, - realm: environment.auth.realm, - clientId: environment.auth.clientId, - }, - initOptions: { - onLoad: "check-sso", - }, - enableBearerInterceptor: false, - }); +export function initializeKeycloak( + keycloak: KeycloakService, + settings: SettingsService, +): Promise { + return keycloak.init({ + config: { + url: settings.settings.keycloak.url, + realm: settings.settings.keycloak.realm, + clientId: settings.settings.keycloak.clientId, + }, + initOptions: { + onLoad: "check-sso", + }, + enableBearerInterceptor: false, + }); } diff --git a/web/src/app/model/config/app-settings.ts b/web/src/app/model/config/app-settings.ts index 8cdedc3..52847e9 100644 --- a/web/src/app/model/config/app-settings.ts +++ b/web/src/app/model/config/app-settings.ts @@ -1,8 +1,26 @@ import { Theme } from "src/app/model/view/theme"; export interface AppSettings { - TermsUrl: string; - PrivacyURL: string; - ImprintURL: string; - Themes: Theme[]; + termsUrl: string; + privacyURL: string; + imprintURL: string; + themes: Theme[]; + loadingScreen: LoadingScreenSettings; + keycloak: KeycloakSettings; + api: ApiSettings; +} + +export interface LoadingScreenSettings { + background: string; + logo: string; +} + +export interface KeycloakSettings { + url: string; + realm: string; + clientId: string; +} + +export interface ApiSettings { + url: string; } diff --git a/web/src/app/model/view/theme.ts b/web/src/app/model/view/theme.ts index c6f4090..e7e9bd8 100644 --- a/web/src/app/model/view/theme.ts +++ b/web/src/app/model/view/theme.ts @@ -1,4 +1,4 @@ export interface Theme { - Label: string; - Name: string; + label: string; + name: string; } diff --git a/web/src/app/modules/shared/shared.module.ts b/web/src/app/modules/shared/shared.module.ts index f2d2877..07f5b8a 100644 --- a/web/src/app/modules/shared/shared.module.ts +++ b/web/src/app/modules/shared/shared.module.ts @@ -61,6 +61,7 @@ import { environment } from "src/environments/environment"; import { InMemoryCache } from "@apollo/client/core"; import { provideHttpClient, withInterceptors } from "@angular/common/http"; import { tokenInterceptor } from "src/app/core/token.interceptor"; +import { SettingsService } from "src/app/service/settings.service"; const sharedModules = [ StepsModule, @@ -128,9 +129,10 @@ const sharedComponents = [ provideHttpClient(withInterceptors([tokenInterceptor])), provideApollo(() => { const httpLink = inject(HttpLink); + const settings = inject(SettingsService); return { - link: httpLink.create({ uri: `${environment.api.url}/graphql` }), + link: httpLink.create({ uri: `${settings.settings.api.url}/graphql` }), cache: new InMemoryCache(), defaultOptions: { diff --git a/web/src/app/service/settings.service.ts b/web/src/app/service/settings.service.ts index 95a3eff..b66a8ec 100644 --- a/web/src/app/service/settings.service.ts +++ b/web/src/app/service/settings.service.ts @@ -8,11 +8,11 @@ import { AppSettings } from "src/app/model/config/app-settings"; providedIn: "root", }) export class SettingsService { - appSettings!: AppSettings; + settings!: AppSettings; constructor(private http: HttpClient) {} - loadSettings(): Promise { + loadSettings(): Promise { return new Promise((resolve, reject) => { this.http .get("/assets/config.json") @@ -23,29 +23,9 @@ export class SettingsService { }), ) .subscribe((settings) => { - this.appSettings = settings; + this.settings = settings; + resolve(); }); }); } - - public getTermsURL(): string { - if (!this.appSettings || !this.appSettings.TermsUrl) { - return "/404"; - } - return this.appSettings.TermsUrl; - } - - public getPrivacyURL(): string { - if (!this.appSettings || !this.appSettings.PrivacyURL) { - return "/404"; - } - return this.appSettings.PrivacyURL; - } - - public getImprintURL(): string { - if (!this.appSettings || !this.appSettings.ImprintURL) { - return "/404"; - } - return this.appSettings.ImprintURL; - } } diff --git a/web/src/assets/config.json b/web/src/assets/config.json index cb45aa4..e067899 100644 --- a/web/src/assets/config.json +++ b/web/src/assets/config.json @@ -1,11 +1,23 @@ { - "TermsUrl": "", - "PrivacyURL": "", - "ImprintURL": "", - "Themes": [ + "termsUrl": "", + "privacyURL": "", + "imprintURL": "", + "themes": [ { - "Label": "Open-redirect", - "Name": "Open-redirect" + "label": "Open-redirect", + "name": "Open-redirect" } - ] + ], + "api": { + "url": "http://localhost:5000/api" + }, + "keycloak": { + "url": "https://keycloak.maxlan.de", + "realm": "develop", + "clientId": "lan-maestro-client-local" + }, + "loadingScreen": { + "background": "https://www.sh-edraft.de/wp-content/uploads/2020/03/IMG_20170731_213039-scaled.jpg", + "logo": "https://www.sh-edraft.de/wp-content/uploads/2020/04/klein_transparent-e1735827600932.png" + } } diff --git a/web/src/environments/environment.development.ts b/web/src/environments/environment.development.ts index 0907fe7..cde8b82 100644 --- a/web/src/environments/environment.development.ts +++ b/web/src/environments/environment.development.ts @@ -4,12 +4,4 @@ export const environment = { production: false, - auth: { - url: "https://auth.sh-edraft.de", - realm: "dev", - clientId: "open-redirect-client", - }, - api: { - url: "https://dev.api.open-redirect.sh-edraft.de", - }, }; diff --git a/web/src/environments/environment.local.ts b/web/src/environments/environment.local.ts index 0130024..cde8b82 100644 --- a/web/src/environments/environment.local.ts +++ b/web/src/environments/environment.local.ts @@ -4,17 +4,4 @@ export const environment = { production: false, - // auth: { - // url: 'https://auth.sh-edraft.de', - // realm: 'dev', - // clientId: 'open-redirect-client', - // }, - auth: { - url: "https://keycloak.maxlan.de", - realm: "develop", - clientId: "lan-maestro-client-local", - }, - api: { - url: "http://localhost:5000/api", - }, }; diff --git a/web/src/environments/environment.production.ts b/web/src/environments/environment.production.ts index 9a3e85c..cde8b82 100644 --- a/web/src/environments/environment.production.ts +++ b/web/src/environments/environment.production.ts @@ -4,12 +4,4 @@ export const environment = { production: false, - auth: { - url: "https://auth.sh-edraft.de", - realm: "maxlan", - clientId: "open-redirect", - }, - api: { - url: "https://api.open-redirect.sh-edraft.de", - }, }; diff --git a/web/src/environments/environment.staging.ts b/web/src/environments/environment.staging.ts index 0599523..cde8b82 100644 --- a/web/src/environments/environment.staging.ts +++ b/web/src/environments/environment.staging.ts @@ -4,12 +4,4 @@ export const environment = { production: false, - auth: { - url: "https://auth.sh-edraft.de", - realm: "develop", - clientId: "open-redirect-client-test", - }, - api: { - url: "https://test.api.open-redirect.sh-edraft.de", - }, }; diff --git a/web/src/environments/environment.ts b/web/src/environments/environment.ts index ead5e1f..66998ae 100644 --- a/web/src/environments/environment.ts +++ b/web/src/environments/environment.ts @@ -4,14 +4,6 @@ export const environment = { production: false, - auth: { - url: "", - realm: "", - clientId: "", - }, - api: { - url: "", - }, }; /*