environment-specific.servic: use document location to get absolute url for server mode

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51347 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2018-03-20 13:46:05 +00:00
parent c77e5ee374
commit eb762038c2
1 changed files with 11 additions and 27 deletions

View File

@ -1,54 +1,38 @@
import { Injectable, OnInit, PLATFORM_ID, Inject } from '@angular/core';
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken } from '@angular/core';
import { isPlatformBrowser} from '@angular/common';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import { EnvProperties } from './env-properties';
import { DOCUMENT } from '@angular/platform-browser';
@Injectable()
export class EnvironmentSpecificService {
// export function createTranslateLoader(http: Http, @Inject('ORIGIN_URL') originUrl: string) {
// return new TranslateHttpLoader(http, originUrl + './assets/i18n/', '.json');
public envSpecific: EnvProperties;
public envSpecificNull: EnvProperties = null;
testBrowser: boolean;
private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
private propertiesUrl = (process.env.PROP_URL)?process.env.PROP_URL:"./assets/env-properties.json";
constructor(private http: Http,@Inject(PLATFORM_ID) platformId: string) {
private propertiesUrl = "/assets/env-properties.json";
// private propertiesUrl = "https://beta.connect.openaire.eu/assets/env-properties.json";
constructor(private http: Http,@Inject(PLATFORM_ID) platformId: string,@Inject(DOCUMENT) private document: any) {
this.testBrowser = isPlatformBrowser(platformId);
if (this.testBrowser) {
//this is only executed on the browser
}
console.log('EnvironmentSpecificService created ' +this.testBrowser);
/*
down vote
import { PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser} from '@angular/common';
...
export class MyComponent {
...
testBrowser: boolean;
constructor(
@Inject(PLATFORM_ID) platformId: string) {
this.testBrowser = isPlatformBrowser(platformId);
if (this.testBrowser) {
//this is only executed on the browser
}
}
*/
}
public loadEnvironment() {
// Only want to do this once - if root page is revisited, it calls this again.
if (this.envSpecific === null || this.envSpecific === undefined) {
console.log('Loading env-properties.json');
console.log('Loading '+ document.location.protocol +"//" + document.location.host+this.propertiesUrl);
return this.http.get(this.propertiesUrl)
return this.http.get(document.location.protocol +"//" + document.location.host+this.propertiesUrl)
.map((data) => data.json())
.toPromise<EnvProperties>();
}