Skip to content

Commit

Permalink
Add standard react env variable for backend services
Browse files Browse the repository at this point in the history
  • Loading branch information
francbartoli committed Nov 23, 2024
1 parent 22d3bc7 commit edeee0d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
#REACT_APP_VECTORTILES_URL=http://localhost/vectortiles
3 changes: 2 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -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
REACT_APP_VECTORTILES_URL=https://clima.arpa.veneto.it/vectortiles
REACT_APP_BACKEND_PUBLIC_URL=https://clima.arpa.veneto.it
3 changes: 2 additions & 1 deletion .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -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
REACT_APP_VECTORTILES_URL=http://192.167.167.61:3001
REACT_APP_BACKEND_PUBLIC_URL=https://arpav.geobeyond.dev
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions production.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 47 additions & 20 deletions src/app/Services/API/Requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class RequestApi extends Http {
}
return this.instance
.get<any>(
'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 },
Expand Down Expand Up @@ -119,7 +121,9 @@ export class RequestApi extends Http {
} else {
this.instance
.get<any>(
'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 => {
Expand Down Expand Up @@ -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);
Expand All @@ -309,7 +315,9 @@ export class RequestApi extends Http {
// Make the request to the API.
return this.instance
.get<any>(
'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) => {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>(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<any>(url);
};

public findMunicipality = (lat, lng) => {
return this.instance.get<any>(
`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})`,
);
};

Expand All @@ -542,7 +561,9 @@ export class RequestApi extends Http {
}
return this.instance
.get<any>(
'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;
Expand All @@ -561,20 +582,26 @@ export class RequestApi extends Http {

const ret = this.instance
.get<any>(
'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;
});
reqs.push(ret);
if (mode === 'forecast') {
const cret = this.instance.get<any>(
'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<any>(
'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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Map/StationsLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Map/VectorWrapperLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit edeee0d

Please sign in to comment.