Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from MahjongPantheon/fix-cors-and-headers
Browse files Browse the repository at this point in the history
Fix some headers issue with CORS
  • Loading branch information
Oleg Klimenko authored Apr 5, 2017
2 parents 8f9b0ee + 737d070 commit 4e46cc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/app/primitives/appstate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import { Outcome, AppOutcome } from '../../interfaces/app';
import { NgZone } from '@angular/core';
import { NgZone, isDevMode } from '@angular/core';
import { getHan, getFixedFu } from '../yaku-values';
import { Outcome as OutcomeType, Player } from '../../interfaces/common';
import { YakuId } from '../yaku';
Expand Down Expand Up @@ -113,6 +113,7 @@ export class AppState {
this.api.getGameConfig(),
this.api.getTimerState()
];

Promise.all(promises).then(([games, playerInfo, gameConfig, timerState]) => {
this._currentPlayerDisplayName = playerInfo.displayName;
this._currentPlayerId = playerInfo.id;
Expand Down Expand Up @@ -140,6 +141,8 @@ export class AppState {
window.localStorage.removeItem('authToken');
this._reset();
this.reinit();
} else if (isDevMode()) {
console.error('Caught error or exception: ', e);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/riichiApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class RiichiApiService {
.post(config.apiUrl, jsonRpcBody, { headers: commonHeaders })
.toPromise()
.then<RET_TYPE>((response) => {
this._checkCompatibility(response.headers.get('X-Api-Headers'));
this._checkCompatibility(response.headers.get('x-api-version')); // for some reason headers are lowercase
const json = response.json();
if (json.error) {
if (isDevMode()) {
Expand All @@ -151,7 +151,7 @@ export class RiichiApiService {
}

private _checkCompatibility(versionString) {
const [major, minor] = versionString.split('.').map((v) => parseInt(v, 10));
const [major, minor] = (versionString || '').split('.').map((v) => parseInt(v, 10));
const [localMajor, localMinor] = config.apiVersion;
if (major !== localMajor) {
console.error('API major version mismatch. Update your app or API instance!');
Expand Down

0 comments on commit 4e46cc3

Please sign in to comment.