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.isLoggedIn = user !== null && user !== undefined;
console.warn("isLoggedIn");
});
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 { 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<void> {
return (): Promise<void> =>
new Promise<void>((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,

View File

@ -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;
}
}

View File

@ -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(() => {});
}

View File

@ -1,12 +1,12 @@
<div class="flex items-center justify-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 inset-0 bg-black opacity-70 rounded-xl"></div>
<div class="relative logo flex justify-center items-center">
<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">
</div>

View File

@ -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<ShortUrlDto | undefined>(`${environment.api.url}/find/${shortUrl}`)
.get<ShortUrlDto | undefined>(`${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);
});

View File

@ -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<boolean> {
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,
});
}

View File

@ -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;
}

View File

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

View File

@ -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: {

View File

@ -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<AppSettings> {
loadSettings(): Promise<void> {
return new Promise((resolve, reject) => {
this.http
.get<AppSettings>("/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;
}
}

View File

@ -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"
}
}

View File

@ -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",
},
};

View File

@ -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",
},
};

View File

@ -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",
},
};

View File

@ -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",
},
};

View File

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