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

Commit

Permalink
fix(url): change the url from hardcode to handle dynamic scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkumars08 committed Apr 6, 2017
1 parent 21a05b8 commit e01710f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ module.exports = function (options) {
'ENV': JSON.stringify(METADATA.ENV),
'API_URL': JSON.stringify(METADATA.API_URL),
'FORGE_URL': JSON.stringify(METADATA.FORGE_URL),
'PUBLIC_PATH': JSON.stringify(METADATA.PUBLIC_PATH)
'PUBLIC_PATH': JSON.stringify(METADATA.PUBLIC_PATH),
'FABRIC8_RECOMMENDER_API': JSON.stringify(METADATA.FABRIC8_RECOMMENDER_API_URL)
}
})
],
Expand Down
26 changes: 23 additions & 3 deletions src/app/stack/stack-analyses.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
import { Injectable } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { Http, Response } from '@angular/http';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';

import { WIT_API_URL } from 'ngx-fabric8-wit';

@Injectable()
export class StackAnalysesService {

private stackAnalysesUrl;
private stackAnalysesUrl: string = '';

private recommenderString: string = 'recommender';
private doubleSlash: string = '//';
private dot: string = '.';
private singleSlash: string = '/';
private v1Extension: string = 'v1';

constructor(
private http: Http,
@Inject(WIT_API_URL) apiUrl: string,
) {
this.stackAnalysesUrl = 'http://recommender.api.prod-preview.openshift.io/api/v1/';
if(process && process.env && process.env.FABRIC8_RECOMMENDER_API) {
this.stackAnalysesUrl = process.env.FABRIC8_RECOMMENDER_API;
} else {
if(apiUrl) {
this.stackAnalysesUrl = apiUrl.replace(this.doubleSlash, this.doubleSlash + this.recommenderString + this.dot);
let len: number = this.stackAnalysesUrl.length;
if(this.stackAnalysesUrl[len - 1] !== this.singleSlash) {
this.stackAnalysesUrl += this.singleSlash;
}
this.stackAnalysesUrl += this.v1Extension + this.singleSlash;
}
}
}

getStackAnalyses(id: string): Observable<any> {
Expand Down

0 comments on commit e01710f

Please sign in to comment.