import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import * as _ from 'lodash'; interface Config { api: string } @Injectable() export class AppSettingsService { private config: Config; constructor(private http: HttpClient) { } bootstrap() { return this.http.get('/api/appsettings') .toPromise() .then(response => { this.config = response; //example https://testmtechapi.azurewebsites.net becomes https://testmtechapi-staging.azurewebsites.net if (_(window.location.hostname).includes('-staging')) { let urlParts = this.config.api.split('.'); if (urlParts.length < 2) { return; } urlParts[0] += '-staging'; this.config.api = urlParts.join('.'); } }); } getConfig() { return this.config; } }