From 5a6e5efec0d615d1423d9218ece2fb22a0fb3600 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 13 Jul 2020 00:37:37 +0200 Subject: [PATCH 1/2] Implement API endpoints --- src/apis.ts | 20 +++++++++++--------- src/app/pages/Vhosts/saga.ts | 5 ++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/apis.ts b/src/apis.ts index 16c3a99..58724cf 100644 --- a/src/apis.ts +++ b/src/apis.ts @@ -1,38 +1,40 @@ const isProduction = process.env.NODE_ENV === 'production'; const mockPath = `${process.env.PUBLIC_URL}/__mocks__/apiRequests`; +export const domain = window.location.hostname; + export const getAppData = isProduction - ? 'localhost/getAppData' + ? `//${domain}/get-app-data.php` : `${mockPath}/getAppData.json`; export const getDockerData = isProduction - ? 'localhost/getDockerData' + ? `//${domain}/get-docker-data.php` : `${mockPath}/getDockerData.json`; export const getMails = isProduction - ? 'localhost/getMails' + ? `//${domain}/get-mails.php` : `${mockPath}/getMails.json`; export const makeGetContainerData = (id: string) => isProduction - ? `localhost/getContainerData/${id}` + ? `//${domain}/get-container-data.php?id=${id}` : `${mockPath}/containerData/${id}.json`; export const makeGetToolsData = (id: string) => isProduction - ? `localhost/getToolsData/${id}` + ? `//${domain}/get-tools.php?id=${id}` : `${mockPath}/tools/${id}.json`; export const getVhosts = isProduction - ? 'localhost/getVhosts' + ? `//${domain}/get-vhosts.php` : `${mockPath}/getVhosts.json`; export const makeGetVhostDirectory = (id: string) => isProduction - ? `localhost/vhosts/directory/${id}` + ? `//${domain}/get-vhost-dir.php?id=${id}` : `${mockPath}/vhosts/directory/${id}.json`; -export const makeGetVhostsDomain = (id: string) => +export const makeGetVhostsDomain = (id: string, tld_suffix: string) => isProduction - ? `localhost/vhosts/domain/${id}` + ? `//${id}.${tld_suffix}/devilbox-api/status.json` : `${mockPath}/vhosts/domain/${id}.json`; diff --git a/src/app/pages/Vhosts/saga.ts b/src/app/pages/Vhosts/saga.ts index 0833a16..a387cbe 100644 --- a/src/app/pages/Vhosts/saga.ts +++ b/src/app/pages/Vhosts/saga.ts @@ -6,6 +6,7 @@ import { makeVhostsSelector, makeDomainErrorSelector, makeDirectoryErrorSelector, + makeTldSuffixSelector, } from './selectors'; import { getVhosts as GET_VHOSTS_API, @@ -39,8 +40,10 @@ function* fetchDirectory(vhostId: string) { } function* fetchDomain(vhostId: string) { + const tldSuffix = yield select(makeTldSuffixSelector); + try { - yield axios.get(makeGetVhostsDomain(vhostId), { timeout: 1000 }); + yield axios.get(makeGetVhostsDomain(vhostId, tldSuffix), { timeout: 1000 }); } catch (e) { const selector = makeDomainErrorSelector(vhostId); const error = yield select(selector); From 40dc4615b16170e2051fff1109ef271829b20d8e Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 13 Jul 2020 00:47:38 +0200 Subject: [PATCH 2/2] Update src/apis.ts Co-authored-by: Tobias Winkler --- src/apis.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/apis.ts b/src/apis.ts index 58724cf..e217991 100644 --- a/src/apis.ts +++ b/src/apis.ts @@ -1,7 +1,9 @@ const isProduction = process.env.NODE_ENV === 'production'; const mockPath = `${process.env.PUBLIC_URL}/__mocks__/apiRequests`; -export const domain = window.location.hostname; +const { + location: { hostname: domain }, +} = window; export const getAppData = isProduction ? `//${domain}/get-app-data.php`