import { Injectable, Inject } from '@angular/core'; import { Configuration } from './configuration'; import { Urls } from './configuration'; import { Observable } from 'rxjs/Observable'; import { Http, Headers, Response } from '@angular/http'; const ENDPOINT_GET_URLS = '/oauth/get_scope_urls'; @Injectable() export class ConfigurationService { config: Configuration; internal_urls: Urls; timerRefreshToken: any; constructor( public http: Http, @Inject('api.config') private apiConfig: Configuration) { this.config = apiConfig; this.internal_urls = new Urls() this.loadUrlsFromAuth().subscribe( res => this.saveUrls(res), err => console.log(err) ) } loadUrlsFromAuth(): Observable { let body = JSON.stringify( { 'client_id': this.config.client_id, 'scope': this.config.account } ); return this.http.post( this.config.bootstrap_url + ENDPOINT_GET_URLS, body ); } saveUrls(res) { let urls = res.json(); if (this.config.force_local !== undefined && this.config.force_local !== false ) { this.internal_urls.canonical = 'http://localhost:8080/zodb1/' + this.config.account; } else { this.internal_urls.canonical = urls.canonical; } if (this.config.force_local !== undefined && this.config.force_local !== false ) { this.internal_urls.proxy = 'http://localhost:8080/zodb1/' + this.config.account; } else { this.internal_urls.proxy = urls.proxy; } if (this.config.force_local !== undefined && this.config.force_local !== false ) { this.internal_urls.websocket = 'http://localhost:8080/zodb1/' + this.config.account; } else { this.internal_urls.websocket = urls.websocket; } } getWSURL() { return this.internal_urls.websocket; } getCanonicalURL() { return this.internal_urls.canonical; } getAuthURL() { return this.config.bootstrap_url; } getProxyURL() { return this.internal_urls.proxy; } save_config() { localStorage.setItem('atlasense_config', JSON.stringify(this.internal_urls)); } }