Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit e01710f

Browse files
committed
fix(url): change the url from hardcode to handle dynamic scenario
1 parent 21a05b8 commit e01710f

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

config/webpack.dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ module.exports = function (options) {
6969
'ENV': JSON.stringify(METADATA.ENV),
7070
'API_URL': JSON.stringify(METADATA.API_URL),
7171
'FORGE_URL': JSON.stringify(METADATA.FORGE_URL),
72-
'PUBLIC_PATH': JSON.stringify(METADATA.PUBLIC_PATH)
72+
'PUBLIC_PATH': JSON.stringify(METADATA.PUBLIC_PATH),
73+
'FABRIC8_RECOMMENDER_API': JSON.stringify(METADATA.FABRIC8_RECOMMENDER_API_URL)
7374
}
7475
})
7576
],

src/app/stack/stack-analyses.service.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, Inject } from '@angular/core';
22
import { Http, Response } from '@angular/http';
33

44
import { Observable } from 'rxjs/Observable';
55
import 'rxjs/add/operator/catch';
66
import 'rxjs/add/operator/map';
77

8+
import { WIT_API_URL } from 'ngx-fabric8-wit';
9+
810
@Injectable()
911
export class StackAnalysesService {
1012

11-
private stackAnalysesUrl;
13+
private stackAnalysesUrl: string = '';
14+
15+
private recommenderString: string = 'recommender';
16+
private doubleSlash: string = '//';
17+
private dot: string = '.';
18+
private singleSlash: string = '/';
19+
private v1Extension: string = 'v1';
1220

1321
constructor(
1422
private http: Http,
23+
@Inject(WIT_API_URL) apiUrl: string,
1524
) {
16-
this.stackAnalysesUrl = 'http://recommender.api.prod-preview.openshift.io/api/v1/';
25+
if(process && process.env && process.env.FABRIC8_RECOMMENDER_API) {
26+
this.stackAnalysesUrl = process.env.FABRIC8_RECOMMENDER_API;
27+
} else {
28+
if(apiUrl) {
29+
this.stackAnalysesUrl = apiUrl.replace(this.doubleSlash, this.doubleSlash + this.recommenderString + this.dot);
30+
let len: number = this.stackAnalysesUrl.length;
31+
if(this.stackAnalysesUrl[len - 1] !== this.singleSlash) {
32+
this.stackAnalysesUrl += this.singleSlash;
33+
}
34+
this.stackAnalysesUrl += this.v1Extension + this.singleSlash;
35+
}
36+
}
1737
}
1838

1939
getStackAnalyses(id: string): Observable<any> {

0 commit comments

Comments
 (0)