This commit is contained in:
Eugene Pankov
2021-07-25 17:44:43 +02:00
parent 7f94d85d67
commit 23e9e984e3
9 changed files with 26 additions and 55 deletions

View File

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