diff options
Diffstat (limited to 'src/api/server/ServerApi.js')
-rw-r--r-- | src/api/server/ServerApi.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index a5d636b4e..627425948 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -14,8 +14,7 @@ import OrderModel from '../../models/Order'; | |||
14 | 14 | ||
15 | import { sleep } from '../../helpers/async-helpers'; | 15 | import { sleep } from '../../helpers/async-helpers'; |
16 | 16 | ||
17 | import { API } from '../../environment'; | 17 | import { RECIPES_PATH, SERVER_NOT_LOADED } from '../../config'; |
18 | import { RECIPES_PATH } from '../../config'; | ||
19 | import apiBase from '../apiBase'; | 18 | import apiBase from '../apiBase'; |
20 | import { prepareAuthRequest, sendAuthRequest } from '../utils/auth'; | 19 | import { prepareAuthRequest, sendAuthRequest } from '../utils/auth'; |
21 | 20 | ||
@@ -39,8 +38,6 @@ module.paths.unshift( | |||
39 | const { app } = remote; | 38 | const { app } = remote; |
40 | const { default: fetch } = remote.require('electron-fetch'); | 39 | const { default: fetch } = remote.require('electron-fetch'); |
41 | 40 | ||
42 | const SERVER_URL = API; | ||
43 | |||
44 | export default class ServerApi { | 41 | export default class ServerApi { |
45 | recipePreviews = []; | 42 | recipePreviews = []; |
46 | 43 | ||
@@ -121,6 +118,10 @@ export default class ServerApi { | |||
121 | } | 118 | } |
122 | 119 | ||
123 | async userInfo() { | 120 | async userInfo() { |
121 | if (apiBase() === SERVER_NOT_LOADED) { | ||
122 | throw new Error('Server not loaded'); | ||
123 | } | ||
124 | |||
124 | const request = await sendAuthRequest(`${apiBase()}/me`); | 125 | const request = await sendAuthRequest(`${apiBase()}/me`); |
125 | if (!request.ok) { | 126 | if (!request.ok) { |
126 | throw request; | 127 | throw request; |
@@ -163,6 +164,10 @@ export default class ServerApi { | |||
163 | 164 | ||
164 | // Services | 165 | // Services |
165 | async getServices() { | 166 | async getServices() { |
167 | if (apiBase() === SERVER_NOT_LOADED) { | ||
168 | throw new Error('Server not loaded'); | ||
169 | } | ||
170 | |||
166 | const request = await sendAuthRequest(`${apiBase()}/me/services`); | 171 | const request = await sendAuthRequest(`${apiBase()}/me/services`); |
167 | if (!request.ok) { | 172 | if (!request.ok) { |
168 | throw request; | 173 | throw request; |
@@ -287,6 +292,10 @@ export default class ServerApi { | |||
287 | } | 292 | } |
288 | 293 | ||
289 | async getFeatures() { | 294 | async getFeatures() { |
295 | if (apiBase() === SERVER_NOT_LOADED) { | ||
296 | throw new Error('Server not loaded'); | ||
297 | } | ||
298 | |||
290 | const request = await sendAuthRequest(`${apiBase()}/features`); | 299 | const request = await sendAuthRequest(`${apiBase()}/features`); |
291 | if (!request.ok) { | 300 | if (!request.ok) { |
292 | throw request; | 301 | throw request; |
@@ -449,7 +458,7 @@ export default class ServerApi { | |||
449 | 458 | ||
450 | // News | 459 | // News |
451 | async getLatestNews() { | 460 | async getLatestNews() { |
452 | const url = `${apiBase()}/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`; | 461 | const url = `https://api.getferdi.com/v1/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`; |
453 | const request = await sendAuthRequest(url); | 462 | const request = await sendAuthRequest(url); |
454 | if (!request.ok) throw request; | 463 | if (!request.ok) throw request; |
455 | const data = await request.json(); | 464 | const data = await request.json(); |
@@ -459,14 +468,18 @@ export default class ServerApi { | |||
459 | } | 468 | } |
460 | 469 | ||
461 | async hideNews(id) { | 470 | async hideNews(id) { |
462 | const request = await sendAuthRequest(`${apiBase()}/news/${id}/read`); | 471 | const request = await sendAuthRequest(`https://api.getferdi.com/v1/news/${id}/read`); |
463 | if (!request.ok) throw request; | 472 | if (!request.ok) throw request; |
464 | debug('ServerApi::hideNews resolves', id); | 473 | debug('ServerApi::hideNews resolves', id); |
465 | } | 474 | } |
466 | 475 | ||
467 | // Health Check | 476 | // Health Check |
468 | async healthCheck() { | 477 | async healthCheck() { |
469 | const request = await sendAuthRequest(`${SERVER_URL}/health`, { | 478 | if (apiBase() === SERVER_NOT_LOADED) { |
479 | throw new Error('Server not loaded'); | ||
480 | } | ||
481 | |||
482 | const request = await sendAuthRequest(`${apiBase(false)}/health`, { | ||
470 | method: 'GET', | 483 | method: 'GET', |
471 | }, false); | 484 | }, false); |
472 | if (!request.ok) { | 485 | if (!request.ok) { |