From c82a7f0fa15fa4d53a38a77ee6263321c90a9e93 Mon Sep 17 00:00:00 2001 From: Kevin Reis Date: Tue, 9 Feb 2021 15:34:56 +0100 Subject: [PATCH] Add retrospective API url injection --- frontend/package.json | 2 +- frontend/src/configs/api.config.ts | 16 ++++++++++++++++ frontend/src/services/UserStatsService.ts | 6 +++--- frontend/yarn.lock | 8 ++++---- 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 frontend/src/configs/api.config.ts diff --git a/frontend/package.json b/frontend/package.json index a976d27..5966189 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,7 +10,7 @@ "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", "@types/jest": "^24.0.0", - "@types/node": "^12.0.0", + "@types/node": "^14.14.25", "husky": "^4.3.7", "lint-staged": "^10.5.3", "prettier": "^2.2.1", diff --git a/frontend/src/configs/api.config.ts b/frontend/src/configs/api.config.ts new file mode 100644 index 0000000..b7966e3 --- /dev/null +++ b/frontend/src/configs/api.config.ts @@ -0,0 +1,16 @@ +export default class APIConfiguration { + private static API_DEV = "https://api.beta.tsotr.humenius.me" + private static API_PROD = "https://api.tsotr.humenius.me" + private static API_LOCAL = "http://localhost:3500" + + public static getUrl = (): string => { + switch (process.env.NODE_ENV) { + case 'production': + return APIConfiguration.API_PROD; + case 'development': + return APIConfiguration.API_DEV; + default: + return APIConfiguration.API_LOCAL; + } + } +} \ No newline at end of file diff --git a/frontend/src/services/UserStatsService.ts b/frontend/src/services/UserStatsService.ts index cbdc4ed..ad81eeb 100644 --- a/frontend/src/services/UserStatsService.ts +++ b/frontend/src/services/UserStatsService.ts @@ -1,10 +1,10 @@ +import APIConfiguration from "../configs/api.config"; import RequestError from "../models/RequestError"; import UserStatsResponse from "../models/UserStatsResponse"; export default class UserStatsService { - private static apiURL = 'https://api.tsotr.humenius.me/stats' - //private static apiURL = 'http://localhost:3500/stats' + private static readonly API_URL = APIConfiguration.getUrl(); private static requestInit: RequestInit = { method: 'GET', @@ -14,7 +14,7 @@ export default class UserStatsService { }; public static async getStats(seasonId?: string): Promise { - return fetch(`${this.apiURL}/season/${seasonId ?? ''}`, this.requestInit) + return fetch(`${UserStatsService.API_URL}/stats/season/${seasonId ?? ''}`, this.requestInit) .then(res => UserStatsService.checkResponse(res)) .then(data => data.json()) .then(data => { diff --git a/frontend/yarn.lock b/frontend/yarn.lock index b6decf3..08f9813 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1716,10 +1716,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.20.tgz#f7974863edd21d1f8a494a73e8e2b3658615c340" integrity sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A== -"@types/node@^12.0.0": - version "12.19.12" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.12.tgz#04793c2afa4ce833a9972e4c476432e30f9df47b" - integrity sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw== +"@types/node@^14.14.25": + version "14.14.25" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.25.tgz#15967a7b577ff81383f9b888aa6705d43fbbae93" + integrity sha512-EPpXLOVqDvisVxtlbvzfyqSsFeQxltFbluZNRndIb8tr9KiBnYNLzrc1N3pyKUCww2RNrfHDViqDWWE1LCJQtQ== "@types/parse-json@^4.0.0": version "4.0.0"