[Library | Trunk]: Get properties from enviroment
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58888 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
7a42282e45
commit
76af144f41
|
@ -1,4 +1,4 @@
|
|||
import {Inject, Injectable, Optional, PLATFORM_ID} from '@angular/core';
|
||||
import {Inject, Injectable, Optional} from '@angular/core';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {BehaviorSubject, of} from 'rxjs';
|
||||
|
||||
|
@ -6,11 +6,8 @@ import {Request} from 'express';
|
|||
import {REQUEST} from '@nguniversal/express-engine/tokens';
|
||||
|
||||
import {EnvProperties} from './env-properties';
|
||||
import {map} from "rxjs/operators";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
|
||||
//export const REQUEST_TOKEN = new InjectionToken<Request>('request');
|
||||
|
||||
@Injectable()
|
||||
export class EnvironmentSpecificService {
|
||||
|
||||
|
@ -24,63 +21,21 @@ export class EnvironmentSpecificService {
|
|||
}
|
||||
|
||||
public loadEnvironment() {
|
||||
// Only want to do this once - if root page is revisited, it calls this again.
|
||||
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
var domain = this.getDomain();
|
||||
var location = this.getFullUrl();
|
||||
// console.log('loadEnvironment: Loading '+ location);
|
||||
return this.http.get<EnvProperties>(location)
|
||||
.pipe(map((data) => {
|
||||
var properties:EnvProperties=data;//.json();
|
||||
properties.domain = domain;
|
||||
this.envSpecific = properties;
|
||||
return properties;
|
||||
}))
|
||||
.toPromise<EnvProperties>();
|
||||
}
|
||||
// console.log('loadEnvironment: already loaded ');
|
||||
return Promise.resolve(this.envSpecific);
|
||||
}
|
||||
|
||||
public subscribeEnvironment() {
|
||||
// Only want to do this once - if root page is revisited, it calls this again.
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
var domain = this.getDomain();
|
||||
var location = this.getFullUrl();
|
||||
// console.log('subscribeEnvironment: Loading '+ location);
|
||||
return this.http.get<EnvProperties>(location)
|
||||
.pipe(map((data) => {
|
||||
var properties:EnvProperties=data;//.json();
|
||||
properties.domain = domain;
|
||||
this.envSpecific = properties;
|
||||
return properties;
|
||||
}))
|
||||
|
||||
this.envSpecific = properties;
|
||||
}
|
||||
// console.log('subscribeEnvironment: already loaded ');
|
||||
return of(this.envSpecific);
|
||||
}
|
||||
getFullUrl(){
|
||||
var location ="";
|
||||
var domain = "";
|
||||
if (typeof document == 'undefined') {
|
||||
//let req = this.injector.get('request');
|
||||
//let req: Request = this.injector.get(REQUEST_TOKEN);
|
||||
domain = this.request.get('host').split(":")[0];
|
||||
location = (domain.indexOf(".openaire.eu")!=-1?"https://":"http://")+ this.request.get('host') + this.propertiesPath;
|
||||
}else{
|
||||
let baseUrl = (document && document.getElementsByTagName('base'))?document.getElementsByTagName('base')[0].href.split(document.location.host)[1]:"/";
|
||||
location = document.location.protocol +"//" + document.location.host + baseUrl + this.propertiesPath;
|
||||
domain = document.location.hostname;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
getDomain(){
|
||||
var domain = "";
|
||||
if (typeof document == 'undefined') {
|
||||
//let req = this.injector.get('request');
|
||||
//let req: Request = this.injector.get(REQUEST_TOKEN);
|
||||
domain = this.request.get('host').split(":")[0];
|
||||
}else{
|
||||
domain = document.location.hostname;
|
||||
|
@ -93,10 +48,7 @@ export class EnvironmentSpecificService {
|
|||
if (es === null || es === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.envSpecific = es;
|
||||
//console.log(this.envSpecific);
|
||||
|
||||
if (this.envSpecificSubject) {
|
||||
this.envSpecificSubject.next(this.envSpecific);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue