Skip to content

Commit

Permalink
feat(server): one domain for all
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Mar 17, 2017
1 parent 00e13aa commit 32ea47f
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 46 deletions.
14 changes: 5 additions & 9 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ A few servers are set up for this project and the settings for them are availabl
These are the default values that can be altered via an override:
```JavaScript
{
httpServer: {
host: 'localhost',
port: 8080
},
staticServer: {
host: 'localhost',
host: '127.0.0.1',
port: 80,
static: {
port: 8081
},
matchServer: {
host: 'localhost',
match: {
port: 8082,
sampleSize: 32
},
apiVersions: {
'summoner': 'v1.4',
'matchlist': 'v2.2',
'match': 'v2.2',
'static-data': 'v1.2',
'static-data': 'v1.2'
},
gameTime: 45 * 60 * 1000
}
Expand Down
24 changes: 19 additions & 5 deletions config/build/webpack.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ module.exports = (options) => {
removeStyleLinkTypeAttributes: true
},
baseUrl: '/',
host: settings.httpServer.host,
port: settings.httpServer.port,
host: settings.host,
port: settings.port,
ENV: ENV,
version: pkg.version,
dependencies: pkg.dependencies
Expand All @@ -97,11 +97,25 @@ module.exports = (options) => {
performance: {hints: options.dev ? false : 'error'},

devServer: {
port: settings.httpServer.port,
host: settings.httpServer.host,
port: settings.port,
host: settings.host,
historyApiFallback: true,
watchOptions: {aggregateTimeout: 300, poll: 1000},
headers: {'Cache-Control': 'public, max-age=31536000'}
headers: {'Cache-Control': 'public, max-age=31536000'},
proxy: {
'/staticapi': {
target: 'https://127.0.0.1:' + settings.static.port,
pathRewrite: {'^/staticapi' : ''},
changeOrigin: true,
secure: false
},
'/matchapi': {
target: 'https://127.0.0.1:' + settings.match.port,
pathRewrite: {'^/matchapi' : ''},
changeOrigin: true,
secure: false
}
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion config/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let BROWSER_CAPS = {
};

exports.config = {
baseUrl: 'http://' + settings.httpServer.host + ':' + settings.httpServer.port,
baseUrl: 'https://' + settings.domain,

specs: [helpers.root('src/**/*.e2e.ts')],
exclude: [],
Expand Down
9 changes: 6 additions & 3 deletions config/settings.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export declare module settings {
let httpServer: {host: string, port: number};
let staticServer: {host: string, port: number};
let matchServer: {host: string, port: number, sampleSize: number};
let host: string
let port: number;
let domain: string;
let static: {port: number};
let match: {port: number, sampleSize: number};
let sampleSize: number;
let apiVersions: {
summoner: string,
matchlist: string,
Expand Down
14 changes: 10 additions & 4 deletions config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ try {
} catch (e) {
}

console.log('user settings:');
console.log(settings);

var exportSettings = helpers.merge(settings, {
httpServer: {host: 'localhost', port: 8080},
staticServer: {host: 'localhost', port: 8081},
matchServer: {host: 'localhost', port: 8082, sampleSize: 32},
host: '127.0.0.1',
port: 80,
static: {port: 8081},
match: {port: 8082, sampleSize: 32},
apiVersions: {
'summoner': 'v1.4',
'matchlist': 'v2.2',
'match': 'v2.2',
'static-data': 'v1.2',
'static-data': 'v1.2'
},
gameTime: 45 * 60 * 1000
});

exportSettings.domain = exportSettings.host + (exportSettings.port ? ':' + exportSettings.port : '')

exportSettings['settings'] = exportSettings;
module.exports = exportSettings;
2 changes: 1 addition & 1 deletion src/client/build/graph/graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class GraphComponent implements OnInit {
line()
.x((_, i) => {
return this.xScaleTime.get()(
i * (settings.gameTime / (settings.matchServer.sampleSize - 1)));
i * (settings.gameTime / (settings.match.sampleSize - 1)));
})
.y((d: any) => {
return this.yScaleSamples.get()(d);
Expand Down
2 changes: 1 addition & 1 deletion src/client/build/items/items.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('ItemsComponent', () => {
component.addTime(item2);
expect(item2.time)
.toBe(
(settings.gameTime / settings.matchServer.sampleSize) / component.samples.gold[1] *
(settings.gameTime / settings.match.sampleSize) / component.samples.gold[1] *
item2.gold.total);
}));

Expand Down
2 changes: 1 addition & 1 deletion src/client/build/items/items.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class ItemsComponent implements OnInit {
let itemGold = (item.gold.total * item.bundle) - item.discount;
item.time = this.getTime(
this.samples.gold, goldOffset + itemGold, settings.gameTime,
settings.matchServer.sampleSize);
settings.match.sampleSize);
goldOffset += itemGold;
}
return items;
Expand Down
6 changes: 2 additions & 4 deletions src/client/services/lolapi.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ describe('LolApiService', () => {
inject([LolApiService], (service) => {
expect(service.getEndpoint(Endpoint.static, 'region'))
.toBe(
'https://' + settings.staticServer.host + ':' + settings.staticServer.port +
'/static-data/region/v1.2');
'https://' + settings.domain + '/staticapi/static-data/region/v1.2');
}));

it('should get the correct resolved link to the match-server',
inject([LolApiService], (service) => {
expect(service.getEndpoint(Endpoint.match, 'region'))
.toBe(
'https://' + settings.matchServer.host + ':' + settings.matchServer.port +
'/region');
'https://' + settings.domain + '/matchapi/region');
}));

it('should not get incorrect params', inject([LolApiService], (service) => {
Expand Down
8 changes: 3 additions & 5 deletions src/client/services/lolapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class LolApiService {
return this.getParam(2).mergeMap(
(summonerName) => this.getParam(3).mergeMap(
(championKey) => this.getMatchData(
summonerName, championKey, settings.gameTime, settings.matchServer.sampleSize)));
summonerName, championKey, settings.gameTime, settings.match.sampleSize)));
}


Expand All @@ -101,11 +101,9 @@ export class LolApiService {
private getEndpoint(endpoint: Endpoint, region: string): string {
switch (endpoint) {
case Endpoint.static:
return 'https://' + settings.staticServer.host + ':' + settings.staticServer.port +
'/static-data/' + region + '/v1.2';
return 'https://' + settings.domain + '/staticapi/static-data/' + region + '/v1.2';
default:
return 'https://' + settings.matchServer.host + ':' + settings.matchServer.port + '/' +
region;
return 'https://' + settings.domain + '/matchapi/' + region;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/match/match.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Match', () => {
let serverResponse: any = new MockServerResponse();

match.get(
'euw', 'DinosHaveNoLife', '123', settings.gameTime, settings.matchServer.sampleSize,
'euw', 'DinosHaveNoLife', '123', settings.gameTime, settings.match.sampleSize,
incomingMessage, serverResponse);

expect(serverResponse.getHeader('test')).toBe('test');
Expand Down
3 changes: 1 addition & 2 deletions src/server/match/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {getPathname, getQuery, Server} from '../server';
import {Match} from './match';
import {Summoner} from './summoner';

let server =
new Server(settings.matchServer.host || 'localhost', settings.matchServer.port || 8081);
let server = new Server(settings.match.port, {maxAge: 1000 * 60 * 60 * 10});

let summoner = new Summoner(server);
let match = new Match(server);
Expand Down
13 changes: 6 additions & 7 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export class Server {
public champions: Array<Array<string>> = [];

public headers = {
'Access-Control-Allow-Origin':
'https://' + settings.httpServer.host + ':' + settings.httpServer.port,
'Access-Control-Allow-Origin': 'https://' + settings.domain,
'content-type': 'application/json'
};

Expand All @@ -67,7 +66,7 @@ export class Server {

private cache;

constructor(private host: string, private port: number, cacheSettings?: any) {
constructor(private port: number, cacheSettings?: any) {
this.cache = lru(this.merge(cacheSettings, {
max: 1048000,
length: (n) => {
Expand All @@ -76,16 +75,16 @@ export class Server {
maxAge: 1000 * 60 * 60 * 2
}));

this.merge({Origin: 'https://' + this.host + ':' + this.port}, this.options.headers);
this.merge({Origin: 'https://' + settings.domain}, this.options.headers);
}

public run(callback: (req: IncomingMessage, resp: ServerResponse) => void): void {
this.preRun();
let server = https.createServer(ssl, (request: IncomingMessage, response: ServerResponse) => {
this.handleRequest(request, response, callback);
});
server.listen(this.port, this.host);
console.log(this.host + ':' + this.port);
server.listen(this.port);
console.log('listening on port: ' + this.port);
}

public sendRequest(
Expand Down Expand Up @@ -231,7 +230,7 @@ export class Server {
'User-Agent': 'Legend-Builder',
'Accept-Language': 'en-US',
'Accept-Charset': 'ISO-8859-1,utf-8',
Origin: 'https://' + this.host + ':' + this.port
Origin: 'https://' + settings.domain
}
};

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 @@ -3,7 +3,7 @@ import {IncomingMessage, ServerResponse} from 'http';
import {settings} from '../../../config/settings';
import {getPathname, HostResponse, Server} from '../server';

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

let baseUrl = server.getBaseUrl();

Expand Down
2 changes: 1 addition & 1 deletion src/server/testing/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class MockServer extends Server {
public mockCache: {url: string, data: any} = {url: '', data: ''};

constructor() {
super('', 1234);
super(1234);
}

public sendRequest(url: string, _region: string, callback: (response: HostResponse) => void):
Expand Down

0 comments on commit 32ea47f

Please sign in to comment.