Project

General

Profile

« Previous | Next » 

Revision 51347

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

View differences:

environment-specific.service.ts
1
import { Injectable, OnInit, PLATFORM_ID, Inject } from '@angular/core';
1
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken } 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';
5 5
import 'rxjs/add/operator/map';
6
import 'rxjs/add/operator/catch';
7 6
import 'rxjs/add/operator/toPromise';
8 7

  
9 8
import { EnvProperties } from './env-properties';
9
import { DOCUMENT } from '@angular/platform-browser';
10 10

  
11 11
@Injectable()
12 12
export class EnvironmentSpecificService {
13

  
13
  // export function createTranslateLoader(http: Http, @Inject('ORIGIN_URL') originUrl: string) {
14
  // return new TranslateHttpLoader(http, originUrl + './assets/i18n/', '.json');
14 15
  public envSpecific: EnvProperties;
15 16
  public envSpecificNull: EnvProperties = null;
16 17
  testBrowser: boolean;
17 18
  private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
18
  private propertiesUrl = (process.env.PROP_URL)?process.env.PROP_URL:"./assets/env-properties.json";
19
  constructor(private http: Http,@Inject(PLATFORM_ID) platformId: string) {
19
  private propertiesUrl = "/assets/env-properties.json";
20

  
21

  
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) {
20 24
      this.testBrowser = isPlatformBrowser(platformId);
21 25
      if (this.testBrowser) {
22 26
          //this is only executed on the browser
23 27
      }
24
    console.log('EnvironmentSpecificService created ' +this.testBrowser);
25
/*
26

  
27
down vote
28

  
29

  
30
import { PLATFORM_ID, Inject } from '@angular/core';
31
import { isPlatformBrowser} from '@angular/common';
32
...
33
export class MyComponent {
34
...
35
    testBrowser: boolean;
36
    constructor(
37
        @Inject(PLATFORM_ID) platformId: string) {
38
            this.testBrowser = isPlatformBrowser(platformId);
39
            if (this.testBrowser) {
40
                //this is only executed on the browser
41
            }
42
    }
43
*/
44 28
  }
45 29

  
46 30
  public loadEnvironment() {
47 31
      // Only want to do this once - if root page is revisited, it calls this again.
48 32
      if (this.envSpecific === null || this.envSpecific === undefined) {
49
        console.log('Loading env-properties.json');
33
        console.log('Loading  '+ document.location.protocol +"//" + document.location.host+this.propertiesUrl);
50 34

  
51
        return this.http.get(this.propertiesUrl)
35
        return this.http.get(document.location.protocol +"//" + document.location.host+this.propertiesUrl)
52 36
            .map((data) => data.json())
53 37
            .toPromise<EnvProperties>();
54 38
      }

Also available in: Unified diff