2021-07-25 14:00:22 +02:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
|
|
|
export class CommonService {
|
2021-07-25 14:38:14 +02:00
|
|
|
private configPromise: Promise<any>
|
|
|
|
|
backendURL$: Promise<string>
|
2021-07-25 14:00:22 +02:00
|
|
|
|
2021-07-25 14:38:14 +02:00
|
|
|
constructor () {
|
|
|
|
|
this.configPromise = this.getConfig()
|
|
|
|
|
this.backendURL$ = this.configPromise.then(cfg => {
|
|
|
|
|
let backendURL = cfg.backendURL
|
|
|
|
|
if (backendURL.endsWith('/')) {
|
|
|
|
|
backendURL = backendURL.slice(0, -1)
|
2021-07-25 14:00:22 +02:00
|
|
|
}
|
2021-07-25 14:38:14 +02:00
|
|
|
return backendURL
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async getConfig () {
|
|
|
|
|
return (await fetch('/config.json')).json()
|
2021-07-25 14:00:22 +02:00
|
|
|
}
|
|
|
|
|
}
|