From 5a766a809dc7f1c5749525d58eef010201536a6d Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 1 Oct 2020 20:53:02 -0500 Subject: [PATCH] remove ajax for json requests --- server/scripts/index.js | 4 ++++ server/scripts/modules/navigation.js | 7 +------ server/scripts/modules/utilities.js | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/server/scripts/index.js b/server/scripts/index.js index bdbec4a..bfd5f4f 100644 --- a/server/scripts/index.js +++ b/server/scripts/index.js @@ -180,7 +180,11 @@ const index = (() => { doRedirectToGeometry(overrides[suggestion.value]); } else { request = $.ajax({ +<<<<<<< Updated upstream url: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', +======= + url: location.protocol + 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', +>>>>>>> Stashed changes data: { text: suggestion.value, magicKey: suggestion.data, diff --git a/server/scripts/modules/navigation.js b/server/scripts/modules/navigation.js index 9d28f08..8f7fb99 100644 --- a/server/scripts/modules/navigation.js +++ b/server/scripts/modules/navigation.js @@ -57,12 +57,7 @@ const navigation = (() => { const point = await utils.weather.getPoint(latLon.lat, latLon.lon); // get stations - const stationsResponse = await fetch(point.properties.observationStations, { - method: 'GET', - mode: 'cors', - type: 'GET', - }); - const stations = await stationsResponse.json(); + const stations = utils.fetch.json(point.properties.observationStations); const StationId = stations.features[0].properties.stationIdentifier; diff --git a/server/scripts/modules/utilities.js b/server/scripts/modules/utilities.js index 213ca30..58e191c 100644 --- a/server/scripts/modules/utilities.js +++ b/server/scripts/modules/utilities.js @@ -182,6 +182,18 @@ const utils = (() => { return url; }; + // ********************************* fetch ******************************************** + const json = async (url) => { + const response = await fetch(url, { + method: 'GET', + mode: 'cors', + type: 'GET', + }); + + if (!response.ok) throw new Error(`Fetch error ${response.status} ${response.statusText} while fetching ${url}`); + return await response.json(); + }; + // return an orderly object return { image: { @@ -219,6 +231,9 @@ const utils = (() => { cors: { rewriteUrl, }, + fetch: { + json, + } }; })();