Load stuff from conf not env

This commit is contained in:
Sven Heidemann 2025-01-02 17:53:10 +01:00
parent 5ffd66d06d
commit fe509af0e6
17 changed files with 97 additions and 107 deletions

View File

@ -22,7 +22,6 @@ export class AppComponent implements OnDestroy {
this.auth.user$.pipe(takeUntil(this.unsubscribe$)).subscribe((user) => { this.auth.user$.pipe(takeUntil(this.unsubscribe$)).subscribe((user) => {
this.isLoggedIn = user !== null && user !== undefined; this.isLoggedIn = user !== null && user !== undefined;
console.warn("isLoggedIn");
}); });
this.sidebar.visible$ this.sidebar.visible$

View File

@ -22,6 +22,7 @@ import { SidebarComponent } from "./components/sidebar/sidebar.component";
import { ErrorHandlingService } from "src/app/service/error-handling.service"; import { ErrorHandlingService } from "src/app/service/error-handling.service";
import { HomeComponent } from "./components/home/home.component"; import { HomeComponent } from "./components/home/home.component";
import { RedirectComponent } from "./components/redirect/redirect.component"; import { RedirectComponent } from "./components/redirect/redirect.component";
import { SettingsService } from "src/app/service/settings.service";
if (environment.production) { if (environment.production) {
Logger.enableProductionMode(); Logger.enableProductionMode();
@ -33,6 +34,20 @@ export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http); return new TranslateHttpLoader(http);
} }
export function appInitializerFactory(
keycloak: KeycloakService,
settings: SettingsService,
): () => Promise<void> {
return (): Promise<void> =>
new Promise<void>((resolve, reject) => {
settings
.loadSettings()
.then(() => initializeKeycloak(keycloak, settings))
.then(() => resolve())
.catch((error) => reject(error));
});
}
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
@ -71,9 +86,9 @@ export function HttpLoaderFactory(http: HttpClient) {
KeycloakService, KeycloakService,
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: initializeKeycloak, useFactory: appInitializerFactory,
multi: true, multi: true,
deps: [KeycloakService], deps: [KeycloakService, SettingsService],
}, },
{ {
provide: ErrorHandler, provide: ErrorHandler,

View File

@ -10,14 +10,14 @@ export class FooterComponent {
constructor(private settings: SettingsService) {} constructor(private settings: SettingsService) {}
get termsUrl(): string { get termsUrl(): string {
return this.settings.getTermsURL(); return this.settings.settings.termsUrl;
} }
get privacyUrl(): string { get privacyUrl(): string {
return this.settings.getPrivacyURL(); return this.settings.settings.privacyURL;
} }
get imprintUrl(): string { get imprintUrl(): string {
return this.settings.getImprintURL(); return this.settings.settings.imprintURL;
} }
} }

View File

@ -8,6 +8,7 @@ import { KeycloakService } from "keycloak-angular";
}) })
export class HomeComponent { export class HomeComponent {
constructor(private keycloak: KeycloakService) { constructor(private keycloak: KeycloakService) {
console.warn("home", this.keycloak.isLoggedIn());
if (!this.keycloak.isLoggedIn()) { if (!this.keycloak.isLoggedIn()) {
this.keycloak.login().then(() => {}); this.keycloak.login().then(() => {});
} }

View File

@ -1,12 +1,12 @@
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
<div class="relative w-screen h-screen bg-cover bg-center" <div class="relative w-screen h-screen bg-cover bg-center"
style="background-image: url(https://www.sh-edraft.de/wp-content/uploads/2020/03/IMG_20170731_213039-scaled.jpg)"></div> style="background-image: url({{settings.loadingScreen.background}})"></div>
<div class="absolute w-1/3 h-2/5 rounded-xl p-5 flex flex-col gap-5 justify-center items-center"> <div class="absolute w-1/3 h-2/5 rounded-xl p-5 flex flex-col gap-5 justify-center items-center">
<div class="absolute inset-0 bg-black opacity-70 rounded-xl"></div> <div class="absolute inset-0 bg-black opacity-70 rounded-xl"></div>
<div class="relative logo flex justify-center items-center"> <div class="relative logo flex justify-center items-center">
<img class="h-48" <img class="h-48"
src="https://www.sh-edraft.de/wp-content/uploads/2020/04/klein_transparent-e1735827600932.png" [src]="settings.loadingScreen.logo"
alt="logo"> alt="logo">
</div> </div>

View File

@ -4,6 +4,8 @@ import { Router } from "@angular/router";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { environment } from "src/environments/environment"; import { environment } from "src/environments/environment";
import { ShortUrlDto } from "src/app/model/entities/short-url"; 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({ @Component({
selector: "app-redirect", selector: "app-redirect",
@ -14,10 +16,13 @@ export class RedirectComponent implements OnInit {
defaultSecs = 5; defaultSecs = 5;
secs = -1; secs = -1;
settings: AppSettings = this.settingsService.settings;
constructor( constructor(
private sidebar: SidebarService, private sidebar: SidebarService,
private router: Router, private router: Router,
private http: HttpClient, private http: HttpClient,
private settingsService: SettingsService,
) { ) {
this.sidebar.hide(); this.sidebar.hide();
} }
@ -37,7 +42,7 @@ export class RedirectComponent implements OnInit {
} }
this.http this.http
.get<ShortUrlDto | undefined>(`${environment.api.url}/find/${shortUrl}`) .get<ShortUrlDto | undefined>(`${this.settings.api.url}/find/${shortUrl}`)
.subscribe(async (response) => { .subscribe(async (response) => {
if (!response) { if (!response) {
await this.router.navigate(["/404"]); await this.router.navigate(["/404"]);
@ -45,7 +50,7 @@ export class RedirectComponent implements OnInit {
} }
if (!response.loadingScreen) { if (!response.loadingScreen) {
window.location.href = `${environment.api.url}/redirect/${shortUrl}`; window.location.href = `${this.settings.api.url}/redirect/${shortUrl}`;
return; return;
} }
@ -54,7 +59,7 @@ export class RedirectComponent implements OnInit {
this.secs--; this.secs--;
if (this.secs === 0) { if (this.secs === 0) {
window.location.href = `${environment.api.url}/redirect/${shortUrl}`; window.location.href = `${this.settings.api.url}/redirect/${shortUrl}`;
} }
}, 1000); }, 1000);
}); });

View File

@ -1,13 +1,16 @@
import { KeycloakService } from "keycloak-angular"; import { KeycloakService } from "keycloak-angular";
import { environment } from "src/environments/environment"; import { environment } from "src/environments/environment";
import { SettingsService } from "src/app/service/settings.service";
export function initializeKeycloak(keycloak: KeycloakService) { export function initializeKeycloak(
return () => keycloak: KeycloakService,
keycloak.init({ settings: SettingsService,
): Promise<boolean> {
return keycloak.init({
config: { config: {
url: environment.auth.url, url: settings.settings.keycloak.url,
realm: environment.auth.realm, realm: settings.settings.keycloak.realm,
clientId: environment.auth.clientId, clientId: settings.settings.keycloak.clientId,
}, },
initOptions: { initOptions: {
onLoad: "check-sso", onLoad: "check-sso",

View File

@ -1,8 +1,26 @@
import { Theme } from "src/app/model/view/theme"; import { Theme } from "src/app/model/view/theme";
export interface AppSettings { export interface AppSettings {
TermsUrl: string; termsUrl: string;
PrivacyURL: string; privacyURL: string;
ImprintURL: string; imprintURL: string;
Themes: Theme[]; 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;
} }

View File

@ -1,4 +1,4 @@
export interface Theme { export interface Theme {
Label: string; label: string;
Name: string; name: string;
} }

View File

@ -61,6 +61,7 @@ import { environment } from "src/environments/environment";
import { InMemoryCache } from "@apollo/client/core"; import { InMemoryCache } from "@apollo/client/core";
import { provideHttpClient, withInterceptors } from "@angular/common/http"; import { provideHttpClient, withInterceptors } from "@angular/common/http";
import { tokenInterceptor } from "src/app/core/token.interceptor"; import { tokenInterceptor } from "src/app/core/token.interceptor";
import { SettingsService } from "src/app/service/settings.service";
const sharedModules = [ const sharedModules = [
StepsModule, StepsModule,
@ -128,9 +129,10 @@ const sharedComponents = [
provideHttpClient(withInterceptors([tokenInterceptor])), provideHttpClient(withInterceptors([tokenInterceptor])),
provideApollo(() => { provideApollo(() => {
const httpLink = inject(HttpLink); const httpLink = inject(HttpLink);
const settings = inject(SettingsService);
return { return {
link: httpLink.create({ uri: `${environment.api.url}/graphql` }), link: httpLink.create({ uri: `${settings.settings.api.url}/graphql` }),
cache: new InMemoryCache(), cache: new InMemoryCache(),
defaultOptions: { defaultOptions: {

View File

@ -8,11 +8,11 @@ import { AppSettings } from "src/app/model/config/app-settings";
providedIn: "root", providedIn: "root",
}) })
export class SettingsService { export class SettingsService {
appSettings!: AppSettings; settings!: AppSettings;
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
loadSettings(): Promise<AppSettings> { loadSettings(): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.http this.http
.get<AppSettings>("/assets/config.json") .get<AppSettings>("/assets/config.json")
@ -23,29 +23,9 @@ export class SettingsService {
}), }),
) )
.subscribe((settings) => { .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;
}
} }

View File

@ -1,11 +1,23 @@
{ {
"TermsUrl": "", "termsUrl": "",
"PrivacyURL": "", "privacyURL": "",
"ImprintURL": "", "imprintURL": "",
"Themes": [ "themes": [
{ {
"Label": "Open-redirect", "label": "Open-redirect",
"Name": "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"
} }
]
} }

View File

@ -4,12 +4,4 @@
export const environment = { export const environment = {
production: false, 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",
},
}; };

View File

@ -4,17 +4,4 @@
export const environment = { export const environment = {
production: false, 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",
},
}; };

View File

@ -4,12 +4,4 @@
export const environment = { export const environment = {
production: false, production: false,
auth: {
url: "https://auth.sh-edraft.de",
realm: "maxlan",
clientId: "open-redirect",
},
api: {
url: "https://api.open-redirect.sh-edraft.de",
},
}; };

View File

@ -4,12 +4,4 @@
export const environment = { export const environment = {
production: false, 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",
},
}; };

View File

@ -4,14 +4,6 @@
export const environment = { export const environment = {
production: false, production: false,
auth: {
url: "",
realm: "",
clientId: "",
},
api: {
url: "",
},
}; };
/* /*