oggui/ogWebconsole/src/app/services/config.service.ts

32 lines
701 B
TypeScript

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;
}
get mercureUrl(): string {
return this.config.mercureUrl;
}
}