Skip to content

Commit

Permalink
feat(servers): get the hostname in a generic way
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed May 31, 2016
1 parent ccda0fb commit 4ccc636
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/server/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Match {
}

private getMatchList(region, summonerId, championKey, callback: CallBack) {
let baseUrl = this.server.config.protocol + region + this.server.config.hostname + '/api/lol';
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
var path = baseUrl + region + '/' + settings.apiVersions.matchlist + 'matchlist/by-summoner/' + summonerId;
this.server.sendRequest(path, region, (res: HostResponse) => {
if (res.success && res.json.totalGames >= config.games.min) {
Expand Down Expand Up @@ -174,7 +174,7 @@ export class Match {
}

private getMatch(region: string, summonerId: number, matchId: number, callback: CallBack) {
let baseUrl = this.server.config.protocol + region + this.server.config.hostname + '/api/lol';
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
var path = baseUrl + region + '/' + settings.apiVersions.match + 'match' + matchId + '?includeTimeline=true';
this.server.sendRequest(path, region, (res: HostResponse) => {
if (res.success) {
Expand Down
6 changes: 5 additions & 1 deletion src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export class Server {
this.sendHttpsRequest(options, callback);
}

public getHostname(region?: string) {
return region ? region : 'global' + this.config.hostname;
}

public setCache(url: string, data: any): void {
this.cache.set(url, data);
}
Expand Down Expand Up @@ -208,7 +212,7 @@ export class Server {
}

private getChampions(region: string, callback: (err, result: { region: string, champions?: Array<number> }) => void) {
let championUrl = this.config.protocol + 'global' + this.config.hostname + '/api/lol/static-data/' + region + '/' + settings.apiVersions['static-data'] + '/champion';
let championUrl = this.config.protocol + this.getHostname() + '/api/lol/static-data/' + region + '/' + settings.apiVersions['static-data'] + '/champion';

championUrl = this.addApiKey(championUrl);

Expand Down
2 changes: 1 addition & 1 deletion src/server/static-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {settings} from '../../config/settings';

let server = new Server(settings.staticServer.host, settings.staticServer.port);

let baseUrl = server.config.protocol + 'global' + server.config.hostname + '/api/lol';
let baseUrl = server.config.protocol + server.getHostname() + '/api/lol';

server.run((request: IncomingMessage, response: ServerResponse) => {
let pathname = getPathname(request.url);
Expand Down
2 changes: 1 addition & 1 deletion src/server/summoner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Summoner {
}

public getData(region: string, name: string, callback: (response: HostResponse) => void) {
let baseUrl = this.server.config.protocol + region + this.server.config.hostname + '/api/lol';
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
var path = baseUrl + region + '/' + settings.apiVersions.summoner + '/summoner/by-name/' + name;
this.server.sendRequest(path, region, callback);
}
Expand Down

0 comments on commit 4ccc636

Please sign in to comment.