From edeee0d22084ad77ba0903dd380c7f36156a6f9b Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Sat, 23 Nov 2024 13:14:26 +0100 Subject: [PATCH] Add standard react env variable for backend services --- .env.example | 3 +- .env.production | 3 +- .env.staging | 3 +- Dockerfile | 2 + production.Dockerfile | 1 + src/app/Services/API/Requests/index.ts | 67 +++++++++++++------ src/app/components/Map/StationsLayer.tsx | 3 +- src/app/components/Map/VectorWrapperLayer.tsx | 3 +- src/utils/constants.ts | 3 +- 9 files changed, 62 insertions(+), 26 deletions(-) diff --git a/.env.example b/.env.example index e56c9cb..eeff1c5 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,9 @@ REACT_APP_NAME="Piattaforma proiezioni climatiche" REACT_APP_API_URL=https://clima.arpa.veneto.it/backend REACT_APP_WMS_PROXY_URL=https://clima.arpa.veneto.it REACT_APP_VECTORTILES_URL=https://clima.arpa.veneto.it/vectortiles +REACT_APP_BACKEND_PUBLIC_URL=https://clima.arpa.veneto.it ### LINKING TO LOCAL SERVICES: #REACT_APP_API_URL=http://localhost/backend #REACT_APP_WMS_PROXY_URL=http://localhost -#REACT_APP_VECTORTILES_URL=http://localhost/vectortiles \ No newline at end of file +#REACT_APP_VECTORTILES_URL=http://localhost/vectortiles diff --git a/.env.production b/.env.production index 11e9a12..0895952 100644 --- a/.env.production +++ b/.env.production @@ -2,4 +2,5 @@ GENERATE_SOURCEMAP=false REACT_APP_NAME="Piattaforma proiezioni climatiche" REACT_APP_API_URL=https://clima.arpa.veneto.it/backend REACT_APP_WMS_PROXY_URL=https://clima.arpa.veneto.it -REACT_APP_VECTORTILES_URL=https://clima.arpa.veneto.it/vectortiles \ No newline at end of file +REACT_APP_VECTORTILES_URL=https://clima.arpa.veneto.it/vectortiles +REACT_APP_BACKEND_PUBLIC_URL=https://clima.arpa.veneto.it diff --git a/.env.staging b/.env.staging index 964a3f7..6bba930 100644 --- a/.env.staging +++ b/.env.staging @@ -2,4 +2,5 @@ GENERATE_SOURCEMAP=false REACT_APP_NAME="Piattaforma proiezioni climatiche" REACT_APP_API_URL=http://192.167.167.61:8000 REACT_APP_WMS_PROXY_URL=http://192.167.167.61:8089 -REACT_APP_VECTORTILES_URL=http://192.167.167.61:3001 \ No newline at end of file +REACT_APP_VECTORTILES_URL=http://192.167.167.61:3001 +REACT_APP_BACKEND_PUBLIC_URL=https://arpav.geobeyond.dev diff --git a/Dockerfile b/Dockerfile index db0bbf8..3ee92e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,8 @@ RUN yarn build # Bundle static assets with nginx FROM nginx:1.21.0-alpine as production ENV NODE_ENV production +ARG REACT_APP_BACKEND_PUBLIC_URL +ENV REACT_APP_BACKEND_PUBLIC_URL $REACT_APP_BACKEND_PUBLIC_URL # Copy built assets from builder COPY --from=builder /app/build /usr/share/nginx/html # Add your nginx.conf diff --git a/production.Dockerfile b/production.Dockerfile index 5541e4b..74389b8 100644 --- a/production.Dockerfile +++ b/production.Dockerfile @@ -14,6 +14,7 @@ RUN yarn build # Bundle static assets with nginx FROM nginx:1.21.0-alpine as production ENV NODE_ENV production +ENV REACT_APP_BACKEND_PUBLIC_URL https://clima.arpa.veneto.it # Copy built assets from builder COPY --from=builder /app/build /usr/share/nginx/html # Add your nginx.conf diff --git a/src/app/Services/API/Requests/index.ts b/src/app/Services/API/Requests/index.ts index 54a4698..0df9ce4 100644 --- a/src/app/Services/API/Requests/index.ts +++ b/src/app/Services/API/Requests/index.ts @@ -56,7 +56,9 @@ export class RequestApi extends Http { } return this.instance .get( - 'https://arpav.geobeyond.dev/api/v2/coverages/forecast-data?', + //'https://arpav.geobeyond.dev/api/v2/coverages/forecast-data?', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/forecast-data?', { params: { offset: 0, limit: 100, ...innerConf }, paramsSerializer: { indexes: null }, @@ -119,7 +121,9 @@ export class RequestApi extends Http { } else { this.instance .get( - 'https://arpav.geobeyond.dev/api/v2/municipalities/municipality-centroids', + //'https://arpav.geobeyond.dev/api/v2/municipalities/municipality-centroids', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/municipalities/municipality-centroids', ) .then((x: any) => x.features) .then(x => { @@ -287,7 +291,9 @@ export class RequestApi extends Http { } const fullUrl = - 'https://arpav.geobeyond.dev/api/v2/coverages/coverage-identifiers?' + + //'https://arpav.geobeyond.dev/api/v2/coverages/coverage-identifiers?' + + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/coverage-identifiers?' + filter; console.log(fullUrl); @@ -309,7 +315,9 @@ export class RequestApi extends Http { // Make the request to the API. return this.instance .get( - 'https://arpav.geobeyond.dev/api/v2/coverages/coverage-identifiers?' + + //'https://arpav.geobeyond.dev/api/v2/coverages/coverage-identifiers?' + + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/coverage-identifiers?' + filter, ) .then((x: any) => { @@ -461,11 +469,14 @@ export class RequestApi extends Http { smoothing: boolean = true, uncertainty: boolean = true, ) => { - let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( - 4, - )} ${lat.toFixed( - 4, - )})&datetime=..%2F..&include_coverage_data=true&coverage_data_smoothing=NO_SMOOTHING`; + //let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( + let url = + process.env.REACT_APP_BACKEND_PUBLIC_URL + + `/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( + 4, + )} ${lat.toFixed( + 4, + )})&datetime=..%2F..&include_coverage_data=true&coverage_data_smoothing=NO_SMOOTHING`; if (smoothing) { url += '&coverage_data_smoothing=MOVING_AVERAGE_11_YEARS&coverage_data_smoothing=LOESS_SMOOTHING'; @@ -500,24 +511,32 @@ export class RequestApi extends Http { lng: number, year: number, ) => { - let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( - 4, - )} ${lat.toFixed(4)})&datetime=${year + 1}%2F${ - year - 1 - }&include_coverage_data=true&coverage_data_smoothing=MOVING_AVERAGE_11_YEARS&include_coverage_related_data=true`; + //let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( + let url = + process.env.REACT_APP_BACKEND_PUBLIC_URL + + `/api/v2/coverages/time-series/${serie}?coords=POINT(${lng.toFixed( + 4, + )} ${lat.toFixed(4)})&datetime=${year + 1}%2F${ + year - 1 + }&include_coverage_data=true&coverage_data_smoothing=MOVING_AVERAGE_11_YEARS&include_coverage_related_data=true`; return this.instance.get(url); }; public getBarometroClimatico = () => { - let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/climate-barometer?data_smoothing=MOVING_AVERAGE_11_YEARS&include_uncertainty=true`; + //let url = `https://arpav.geobeyond.dev/api/v2/coverages/time-series/climate-barometer?data_smoothing=MOVING_AVERAGE_11_YEARS&include_uncertainty=true`; + let url = + process.env.REACT_APP_BACKEND_PUBLIC_URL + + `/api/v2/coverages/time-series/climate-barometer?data_smoothing=MOVING_AVERAGE_11_YEARS&include_uncertainty=true`; console.log(url); return this.instance.get(url); }; public findMunicipality = (lat, lng) => { return this.instance.get( - `https://arpav.geobeyond.dev/api/v2/municipalities/municipalities?coords=POINT(${lng} ${lat})`, + //`https://arpav.geobeyond.dev/api/v2/municipalities/municipalities?coords=POINT(${lng} ${lat})`, + process.env.REACT_APP_BACKEND_PUBLIC_URL + + `/api/v2/municipalities/municipalities?coords=POINT(${lng} ${lat})`, ); }; @@ -542,7 +561,9 @@ export class RequestApi extends Http { } return this.instance .get( - 'https://arpav.geobeyond.dev/api/v2/coverages/configuration-parameters?offset=0&limit=100', + //'https://arpav.geobeyond.dev/api/v2/coverages/configuration-parameters?offset=0&limit=100', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/configuration-parameters?offset=0&limit=100', ) .then((d: any) => { return d.items; @@ -561,7 +582,9 @@ export class RequestApi extends Http { const ret = this.instance .get( - 'https://arpav.geobeyond.dev/api/v2/coverages/configuration-parameters?offset=0&limit=100', + //'https://arpav.geobeyond.dev/api/v2/coverages/configuration-parameters?offset=0&limit=100', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/configuration-parameters?offset=0&limit=100', ) .then((d: any) => { return d.items; @@ -569,12 +592,16 @@ export class RequestApi extends Http { reqs.push(ret); if (mode === 'forecast') { const cret = this.instance.get( - 'https://arpav.geobeyond.dev/api/v2/coverages/forecast-variable-combinations', + //'https://arpav.geobeyond.dev/api/v2/coverages/forecast-variable-combinations', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/forecast-variable-combinations', ); reqs.push(cret); } else { const cret = this.instance.get( - 'https://arpav.geobeyond.dev/api/v2/coverages/historical-variable-combinations', + //'https://arpav.geobeyond.dev/api/v2/coverages/historical-variable-combinations', + process.env.REACT_APP_BACKEND_PUBLIC_URL + + '/api/v2/coverages/historical-variable-combinations', ); reqs.push(cret); } diff --git a/src/app/components/Map/StationsLayer.tsx b/src/app/components/Map/StationsLayer.tsx index 4f530a5..74f138b 100644 --- a/src/app/components/Map/StationsLayer.tsx +++ b/src/app/components/Map/StationsLayer.tsx @@ -23,7 +23,8 @@ export const StationsLayer = (props: any) => { let selected = false; // let hovered = false; const container = context.layerContainer || context.map; - const url = 'https://arpav.geobeyond.dev/vector-tiles/stations/{z}/{x}/{y}'; + // const url = 'https://arpav.geobeyond.dev/vector-tiles/stations/{z}/{x}/{y}'; + const url = process.env.REACT_APP_BACKEND_PUBLIC_URL + '/vector-tiles/stations/{z}/{x}/{y}'; context.map.createPane('stations'); // @ts-ignore diff --git a/src/app/components/Map/VectorWrapperLayer.tsx b/src/app/components/Map/VectorWrapperLayer.tsx index b81b335..509d5e5 100644 --- a/src/app/components/Map/VectorWrapperLayer.tsx +++ b/src/app/components/Map/VectorWrapperLayer.tsx @@ -24,7 +24,8 @@ export const VectorWrapperLayer = (props: any) => { let selected = false; - const url = `https://arpav.geobeyond.dev/vector-tiles/municipalities/{z}/{x}/{y}`; + // const url = `https://arpav.geobeyond.dev/vector-tiles/municipalities/{z}/{x}/{y}`; + const url = process.env.REACT_APP_BACKEND_PUBLIC_URL + '/vector-tiles/municipalities/{z}/{x}/{y}'; useEffect(() => { context.map.createPane('municipalities'); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 052131a..5d5c2a9 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,7 +3,8 @@ export const API_URL = 'https://clima.arpa.veneto.it/backend/'; //process.env.RE export const V2_API_URL = 'https://clima.arpa.veneto.it/backend/'; //process.env.REACT_APP_API_URL as string; export const WMS_PROXY_URL = 'https://clima.arpa.veneto.it'; //process.env.REACT_APP_WMS_PROXY_URL as string; export const V2_WMS_PROXY_URL = - 'https://arpav.geobeyond.dev/api/v2/coverages/wms/'; //process.env.REACT_APP_WMS_PROXY_URL as string; + //'https://arpav.geobeyond.dev/api/v2/coverages/wms/'; + process.env.REACT_APP_BACKEND_PUBLIC_URL + '/api/v2/coverages/wms/'; export const VECTORTILES_URL = 'https://clima.arpa.veneto.it/vectortiles/'; //process.env.REACT_APP_VECTORTILES_URL as string; export const V2_VECTORTILES_URL = 'https://clima.arpa.veneto.it/vectortiles/'; //process.env.REACT_APP_VECTORTILES_URL as string;