Merge branch 'develop' of ssh://ognproject.evlt.uma.es:21987/opengnsys/oggui into develop
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details

pull/18/head
Manuel Aranda Rosales 2025-03-11 17:10:11 +01:00
commit 294e85508b
3 changed files with 45 additions and 2 deletions

View File

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

View File

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

View File

@ -0,0 +1,3 @@
{
"apiUrl": "https://127.0.0.1:8443"
}