2020-06-11 18:13:47 +02:00
|
|
|
import {Inject, Injectable, Optional} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {Request} from 'express';
|
2020-06-11 15:53:48 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2020-09-18 15:26:15 +02:00
|
|
|
import {ConnectHelper} from "../../connect/connectHelper";
|
2021-07-14 13:19:57 +02:00
|
|
|
import {REQUEST} from '../tokens';
|
2019-06-03 15:20:36 +02:00
|
|
|
|
2021-04-01 16:24:54 +02:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2018-02-05 14:14:59 +01:00
|
|
|
export class EnvironmentSpecificService {
|
2020-06-12 16:37:40 +02:00
|
|
|
|
2020-06-11 15:53:48 +02:00
|
|
|
constructor(private http: HttpClient, @Optional() @Inject(REQUEST) private request: Request) {
|
2020-09-18 09:57:42 +02:00
|
|
|
if(properties.adminToolsCommunity == "connect") {
|
2020-09-18 15:26:15 +02:00
|
|
|
if(properties.environment == "development"){
|
|
|
|
properties.domain = "https://beta."+(ConnectHelper.getCommunityFromDomain(properties.domain)?ConnectHelper.getCommunityFromDomain(properties.domain):"connect")+".openaire.eu";
|
2020-11-23 13:27:42 +01:00
|
|
|
} else{
|
|
|
|
properties.domain = "https://" + this.getDomain();
|
|
|
|
}
|
|
|
|
} else if(properties.adminToolsPortalType === 'aggregator') {
|
|
|
|
if(properties.environment == "development"){
|
|
|
|
properties.domain = "https://beta.canada.openaire.eu";
|
|
|
|
} else {
|
2020-09-18 15:26:15 +02:00
|
|
|
properties.domain = "https://" + this.getDomain();
|
|
|
|
}
|
2020-09-18 09:57:42 +02:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2020-06-11 15:53:48 +02:00
|
|
|
|
2021-04-01 16:24:54 +02:00
|
|
|
private getDomain() {
|
2020-06-12 16:37:40 +02:00
|
|
|
var domain = "";
|
2021-07-14 13:19:57 +02:00
|
|
|
if (this.request) {
|
2019-06-03 15:20:36 +02:00
|
|
|
domain = this.request.get('host').split(":")[0];
|
2020-06-12 16:37:40 +02:00
|
|
|
} else {
|
2019-06-03 15:20:36 +02:00
|
|
|
domain = document.location.hostname;
|
2020-06-12 16:37:40 +02:00
|
|
|
}
|
|
|
|
return domain;
|
2019-03-01 12:29:52 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|