diff --git a/ogWebconsole/src/app/app.module.ts b/ogWebconsole/src/app/app.module.ts index 132fde0..2007b14 100644 --- a/ogWebconsole/src/app/app.module.ts +++ b/ogWebconsole/src/app/app.module.ts @@ -1,4 +1,5 @@ -import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { NgModule, CUSTOM_ELEMENTS_SCHEMA, APP_INITIALIZER } from '@angular/core'; +import { ConfigService } from './services/config.service'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -134,6 +135,10 @@ export function HttpLoaderFactory(http: HttpClient) { return new TranslateHttpLoader(http, './locale/', '.json'); } +export function initializeApp(configService: ConfigService) { + return () => configService.loadConfig(); +} + @NgModule({ declarations: [ AppComponent, @@ -276,7 +281,14 @@ export function HttpLoaderFactory(http: HttpClient) { multi: true }, provideAnimationsAsync(), - provideHttpClient(withInterceptorsFromDi()) + provideHttpClient(withInterceptorsFromDi()), + ConfigService, + { + provide: APP_INITIALIZER, + useFactory: initializeApp, + deps: [ConfigService], + multi: true + } ], }) export class AppModule { } diff --git a/ogWebconsole/src/app/services/config.service.ts b/ogWebconsole/src/app/services/config.service.ts new file mode 100644 index 0000000..9e881cd --- /dev/null +++ b/ogWebconsole/src/app/services/config.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) +export class ConfigService { + private config: any; + + constructor(private http: HttpClient) {} + + loadConfig() { + return this.http.get('/assets/config.json').pipe( + catchError((error) => { + console.error('Error loading config.json', error); + return of({}); + }) + ).toPromise().then(config => { + this.config = config; + }); + } + + get apiUrl(): string { + return this.config.apiUrl; + } +} \ No newline at end of file diff --git a/ogWebconsole/src/assets/config.json b/ogWebconsole/src/assets/config.json new file mode 100644 index 0000000..66567dd --- /dev/null +++ b/ogWebconsole/src/assets/config.json @@ -0,0 +1,3 @@ +{ + "apiUrl": "https://127.0.0.1:8443" +}