From 6cf6916782f8adec629f1478046ab9f3dd1b6c8e Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Sun, 6 Oct 2024 17:34:05 +0200 Subject: [PATCH 1/8] Add GIS_TOKEN to the fetch request --- src/utils/utils.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index c89d5dc..4bedc32 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -32,8 +32,16 @@ export const handleImageServiceRequest = async (event, variable, setChartData, s }), }; + const token = process.env.GIS_TOKEN; + try { - const response = await fetch(url.toString(), { method: 'GET' }); + const response = await fetch(url.toString(), { + method: 'GET', + headers: { + 'Authorization': `Bearer ${token}`, + 'Referer': 'https://earthdata.gov', + } + }); const results = await response.json(); // const results = mockData; // Uncomment this line to use mockData during testing From fc50f37641e2d78a32e8ec3e7a1b480051f7b9b9 Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Sun, 6 Oct 2024 18:03:03 +0200 Subject: [PATCH 2/8] Change name --- src/utils/utils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 4bedc32..679b120 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -32,9 +32,8 @@ export const handleImageServiceRequest = async (event, variable, setChartData, s }), }; - const token = process.env.GIS_TOKEN; - try { + const token = import.meta.env.VITE_GIS_TOKEN; const response = await fetch(url.toString(), { method: 'GET', headers: { From 9a3981041599cca291934e0502ada83fd5250178 Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Mon, 7 Oct 2024 15:35:03 +0100 Subject: [PATCH 3/8] Update endpoint --- src/config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.json b/src/config.json index 1acd3ce..2d1eac7 100644 --- a/src/config.json +++ b/src/config.json @@ -13,7 +13,7 @@ "mobileVideo": "./monthly_max_ssp126_max12_8192_512x256.mp4", "fallbackImage": "./first_frame_ssp126.png", "service": - "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -45,7 +45,7 @@ "mobileVideo": "./monthly_max_ssp245_max12_8192_1024x512.mp4", "fallbackImage": "./first_frame_ssp245.png", "service": - "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -77,7 +77,7 @@ "mobileVideo": "./monthly_max_ssp370_max12_8192_512x256.mp4", "fallbackImage": "./first_frame_ssp370.png", "service": - "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -109,7 +109,7 @@ "fallbackImage": "./first_frame_ssp585.png", "variable": "tasmax_ssp585", "service": - "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, From dc8f7728edb431da45f7c79d74538ffd4f983cab Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Mon, 7 Oct 2024 16:36:26 +0100 Subject: [PATCH 4/8] Add token fallback --- src/utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 679b120..9bbf158 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -33,7 +33,7 @@ export const handleImageServiceRequest = async (event, variable, setChartData, s }; try { - const token = import.meta.env.VITE_GIS_TOKEN; + const token = import.meta.env.VITE_GIS_TOKEN ?? ''; const response = await fetch(url.toString(), { method: 'GET', headers: { From 92e7b97f1da1f2abd23224ec04230156c79b48de Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Mon, 7 Oct 2024 17:48:43 +0100 Subject: [PATCH 5/8] Update auth header --- src/utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 9bbf158..b6a703a 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -37,7 +37,7 @@ export const handleImageServiceRequest = async (event, variable, setChartData, s const response = await fetch(url.toString(), { method: 'GET', headers: { - 'Authorization': `Bearer ${token}`, + 'X-Esri-Authorization': `Bearer ${token}`, 'Referer': 'https://earthdata.gov', } }); From d2d229dc2f6ad5b1a40cde85c4f742eaf36ef08a Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Mon, 7 Oct 2024 18:51:27 +0100 Subject: [PATCH 6/8] Switch to prod endpoints --- src/config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.json b/src/config.json index 2d1eac7..1acd3ce 100644 --- a/src/config.json +++ b/src/config.json @@ -13,7 +13,7 @@ "mobileVideo": "./monthly_max_ssp126_max12_8192_512x256.mp4", "fallbackImage": "./first_frame_ssp126.png", "service": - "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -45,7 +45,7 @@ "mobileVideo": "./monthly_max_ssp245_max12_8192_1024x512.mp4", "fallbackImage": "./first_frame_ssp245.png", "service": - "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -77,7 +77,7 @@ "mobileVideo": "./monthly_max_ssp370_max12_8192_512x256.mp4", "fallbackImage": "./first_frame_ssp370.png", "service": - "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, @@ -109,7 +109,7 @@ "fallbackImage": "./first_frame_ssp585.png", "variable": "tasmax_ssp585", "service": - "https://gis.earthdata.nasa.gov/eictester/rest/services/tasmax_yearly_median/ImageServer", + "https://gis.earthdata.nasa.gov/eic/rest/services/tasmax_yearly_median/ImageServer", "datetimeRange": ["1950-01-31T00:00:00Z", "2100-12-31T23:59:59Z"], "wcs": false, "active": true, From 28997b543d945242fe22d6901138de2c96ea48bd Mon Sep 17 00:00:00 2001 From: Gjore Milevski Date: Mon, 7 Oct 2024 18:52:40 +0100 Subject: [PATCH 7/8] Use referer from env variable --- src/utils/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index b6a703a..1480dba 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -34,11 +34,12 @@ export const handleImageServiceRequest = async (event, variable, setChartData, s try { const token = import.meta.env.VITE_GIS_TOKEN ?? ''; + const referer = import.meta.env.VITE_REFERER ?? 'https://earth.gov'; const response = await fetch(url.toString(), { method: 'GET', headers: { 'X-Esri-Authorization': `Bearer ${token}`, - 'Referer': 'https://earthdata.gov', + 'Referer': `${referer}`, } }); const results = await response.json(); From 107ad2097c7f059f0e3a5ec0e3ec7ff31670a22a Mon Sep 17 00:00:00 2001 From: Abdelhak Marouane Date: Mon, 7 Oct 2024 13:16:05 -0500 Subject: [PATCH 8/8] Adding env vars --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b654dc6..ad10546 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,6 +72,8 @@ jobs: GOOGLE_TAG_MANAGER_ID: ${{secrets.GOOGLE_TAG_MANAGER_ID}} GOOGLE_TAG_AUTH: ${{secrets.GOOGLE_TAG_AUTH}} GOOGLE_TAG_PREVIEW: ${{secrets.GOOGLE_TAG_PREVIEW}} + VITE_GIS_TOKEN: {{secrets.GIS_TOKEN}} + VITE_REFERER: {{vars.GIS_REFERER}} run: | npm install npm run build