Project

General

Profile

« Previous | Next » 

Revision 52449

Change environment-specific.service.ts to be able to read properties in server side. Had to add a property serverUrl - change it in every deployment
add check for server side before use document in isRouteEnabled.guard.ts & environment-specific.service.ts

View differences:

environment-specific.service.ts
1
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken } from '@angular/core';
1
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken , Optional } from '@angular/core';
2 2
import { isPlatformBrowser} from '@angular/common';
3 3
import { Http, Response, Headers, RequestOptions } from '@angular/http';
4 4
import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx';
......
10 10

  
11 11
@Injectable()
12 12
export class EnvironmentSpecificService {
13
  // export function createTranslateLoader(http: Http, @Inject('ORIGIN_URL') originUrl: string) {
14
  // return new TranslateHttpLoader(http, originUrl + './assets/i18n/', '.json');
13

  
15 14
  public envSpecific: EnvProperties;
16 15
  public envSpecificNull: EnvProperties = null;
17 16
  testBrowser: boolean;
......
19 18
  private propertiesUrl = "/assets/env-properties.json";
20 19

  
21 20

  
22
  // private propertiesUrl = "https://beta.connect.openaire.eu/assets/env-properties.json";
23
  constructor(private http: Http,@Inject(PLATFORM_ID) platformId: string,@Inject(DOCUMENT) private document: any) {
21
  private serverUrl = "http://scoobydoo.di.uoa.gr:4000";
22
  // private serverUrl = "https://beta.explore.openaire.eu";
23
  // private serverUrl = "https://beta.connect.openaire.eu";
24
  constructor(private http: Http,  @Inject(PLATFORM_ID) private platformId: string) {
24 25
      this.testBrowser = isPlatformBrowser(platformId);
25 26
      if (this.testBrowser) {
26 27
          //this is only executed on the browser
27 28
      }
28 29
  }
29

  
30 30
  public loadEnvironment() {
31 31
      // Only want to do this once - if root page is revisited, it calls this again.
32 32
      if (this.envSpecific === null || this.envSpecific === undefined) {
33
        console.log('Loading  '+ document.location.protocol +"//" + document.location.host+this.propertiesUrl);
33
        var location = this.propertiesUrl;
34
        if(typeof document == 'undefined'){
35
          location = this.serverUrl + this.propertiesUrl;
34 36

  
35
        return this.http.get(document.location.protocol +"//" + document.location.host+this.propertiesUrl)
37
        }else{
38
          location = document.location.protocol +"//" + document.location.host+this.propertiesUrl;
39
        }
40
        console.log('Loading  '+ location);
41
        return this.http.get(location)
36 42
            .map((data) => data.json())
37 43
            .toPromise<EnvProperties>();
38 44
      }

Also available in: Unified diff