From a0ac009c44b210df4d79ffedbdd892fe7302d22e Mon Sep 17 00:00:00 2001 From: vantezzen Date: Sun, 27 Oct 2019 10:17:47 +0100 Subject: #146 Add possible fix for 1.1.1.1 hack --- src/api/server/ServerApi.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/api/server/ServerApi.js') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index a5d636b4e..164bc237b 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -14,8 +14,7 @@ import OrderModel from '../../models/Order'; import { sleep } from '../../helpers/async-helpers'; -import { API } from '../../environment'; -import { RECIPES_PATH } from '../../config'; +import { RECIPES_PATH, SERVER_NOT_LOADED } from '../../config'; import apiBase from '../apiBase'; import { prepareAuthRequest, sendAuthRequest } from '../utils/auth'; @@ -39,8 +38,6 @@ module.paths.unshift( const { app } = remote; const { default: fetch } = remote.require('electron-fetch'); -const SERVER_URL = API; - export default class ServerApi { recipePreviews = []; @@ -121,6 +118,10 @@ export default class ServerApi { } async userInfo() { + if (apiBase() === SERVER_NOT_LOADED) { + throw new Error('Server not loaded'); + } + const request = await sendAuthRequest(`${apiBase()}/me`); if (!request.ok) { throw request; @@ -163,6 +164,10 @@ export default class ServerApi { // Services async getServices() { + if (apiBase() === SERVER_NOT_LOADED) { + throw new Error('Server not loaded'); + } + const request = await sendAuthRequest(`${apiBase()}/me/services`); if (!request.ok) { throw request; @@ -287,6 +292,10 @@ export default class ServerApi { } async getFeatures() { + if (apiBase() === SERVER_NOT_LOADED) { + throw new Error('Server not loaded'); + } + const request = await sendAuthRequest(`${apiBase()}/features`); if (!request.ok) { throw request; @@ -466,7 +475,11 @@ export default class ServerApi { // Health Check async healthCheck() { - const request = await sendAuthRequest(`${SERVER_URL}/health`, { + if (apiBase() === SERVER_NOT_LOADED) { + throw new Error('Server not loaded'); + } + + const request = await sendAuthRequest(`${apiBase(false)}/health`, { method: 'GET', }, false); if (!request.ok) { -- cgit v1.2.3-70-g09d2