From 0aeb37b1865247bc6880a43dd0b803605eb3c9ce Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Tue, 11 Jun 2024 18:35:29 +0200 Subject: [PATCH 1/3] Fixed local FE dev server not working Signed-off-by: Emil Balitzki --- frontend/src/components/MapView/DataFetch.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/MapView/DataFetch.tsx b/frontend/src/components/MapView/DataFetch.tsx index 7e54daa0..8e700f2f 100644 --- a/frontend/src/components/MapView/DataFetch.tsx +++ b/frontend/src/components/MapView/DataFetch.tsx @@ -13,8 +13,8 @@ const geojsonGemeindenPolygons: FeatureCollection = // These values will be replaced after build with the .sh script when spinning up docker container. export const currentEnvironment = { - apiBaseHost: "API_GATEWAY_HOST", - apiBasePort: "API_GATEWAY_PORT", + apiGatewayHost: "API_GATEWAY_HOST", + apiGatewayPort: "API_GATEWAY_PORT", }; const useGeoData = ( @@ -41,9 +41,15 @@ const useGeoData = ( default: return ( "http://" + - currentEnvironment.apiBaseHost + + (currentEnvironment.apiGatewayHost === + ["API_", "GATEWAY_", "HOST"].join() + ? currentEnvironment.apiGatewayHost + : "localhost") + ":" + - currentEnvironment.apiBasePort + + (currentEnvironment.apiGatewayPort === + ["API_", "GATEWAY_", "PORT"].join() + ? currentEnvironment.apiGatewayPort + : "8081") + "/api/getDatasetViewportData" ); } From 19f4ed93527deddc281dfa8a4d1aea66a1ea7150 Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Tue, 11 Jun 2024 18:38:24 +0200 Subject: [PATCH 2/3] Added one comment Signed-off-by: Emil Balitzki --- frontend/src/components/MapView/DataFetch.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/MapView/DataFetch.tsx b/frontend/src/components/MapView/DataFetch.tsx index 8e700f2f..be708335 100644 --- a/frontend/src/components/MapView/DataFetch.tsx +++ b/frontend/src/components/MapView/DataFetch.tsx @@ -33,7 +33,8 @@ const useGeoData = ( (tab) => tab.dataset.id === id ); - // Returns the API URL of the endpoint for a specific dataset + // Returns the API URL of the endpoint for a specific dataset. + // The .join() function ensures that this strings will not be replace by the .sh script. const getApiUrlForDataset = (): string => { switch (id) { case "empty_map": From 564b3a6f91295ce93e585a05d822b71eeae2096c Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Tue, 11 Jun 2024 20:06:20 +0200 Subject: [PATCH 3/3] Refactored changes into seperate function Signed-off-by: Emil Balitzki --- frontend/src/components/MapView/DataFetch.tsx | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/MapView/DataFetch.tsx b/frontend/src/components/MapView/DataFetch.tsx index be708335..74176379 100644 --- a/frontend/src/components/MapView/DataFetch.tsx +++ b/frontend/src/components/MapView/DataFetch.tsx @@ -33,26 +33,28 @@ const useGeoData = ( (tab) => tab.dataset.id === id ); - // Returns the API URL of the endpoint for a specific dataset. + // Returns the API Gateway URL for a specific deployment environment // The .join() function ensures that this strings will not be replace by the .sh script. - const getApiUrlForDataset = (): string => { + const getAPIGatewayURL = (): string => { + return ( + "http://" + + (currentEnvironment.apiGatewayHost === ["API_", "GATEWAY_", "HOST"].join() + ? currentEnvironment.apiGatewayHost + : "localhost") + + ":" + + (currentEnvironment.apiGatewayPort === ["API_", "GATEWAY_", "PORT"].join() + ? currentEnvironment.apiGatewayPort + : "8081") + ); + }; + + // Returns the API Gateway URL of the endpoint for a specific dataset. + const getViewportDatasetEndpoint = (): string => { switch (id) { case "empty_map": return ""; default: - return ( - "http://" + - (currentEnvironment.apiGatewayHost === - ["API_", "GATEWAY_", "HOST"].join() - ? currentEnvironment.apiGatewayHost - : "localhost") + - ":" + - (currentEnvironment.apiGatewayPort === - ["API_", "GATEWAY_", "PORT"].join() - ? currentEnvironment.apiGatewayPort - : "8081") + - "/api/getDatasetViewportData" - ); + return getAPIGatewayURL() + "/api/getDatasetViewportData"; } }; @@ -89,9 +91,9 @@ const useGeoData = ( ZoomLevel: zoom, datasetID: id, }; - console.log(getApiUrlForDataset()); + console.log(getViewportDatasetEndpoint()); const response = await axios.get>( - getApiUrlForDataset(), + getViewportDatasetEndpoint(), { params, }