diff --git a/complete/Api/Data/NwsManager.cs b/complete/Api/Data/NwsManager.cs index ea5b196..c981ae9 100644 --- a/complete/Api/Data/NwsManager.cs +++ b/complete/Api/Data/NwsManager.cs @@ -15,12 +15,6 @@ public class NwsManager(HttpClient httpClient, IMemoryCache cache) public async Task GetZonesAsync() { - // To get the live zone data from NWS, uncomment the following code and comment out the return statement below - //var response = await httpClient.GetAsync("https://api.weather.gov/zones?type=forecast"); - //response.EnsureSuccessStatusCode(); - //var content = await response.Content.ReadAsStringAsync(); - //return JsonSerializer.Deserialize(content, options); - return await cache.GetOrCreateAsync("zones", async entry => { if (entry is null) @@ -28,6 +22,18 @@ public class NwsManager(HttpClient httpClient, IMemoryCache cache) entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1); + // To get the live zone data from NWS, uncomment the following code and comment out the return statement below. This is required if you are deploying to ACA + //var response = await httpClient.GetAsync("https://api.weather.gov/zones?type=forecast"); + //response.EnsureSuccessStatusCode(); + //var content = await response.Content.ReadAsStringAsync(); + //var zones = JsonSerializer.Deserialize(content, options); + //return zones?.Features + // ?.Where(f => f.Properties?.ObservationStations?.Count > 0) + // .Select(f => (Zone)f) + // .Distinct() + // .ToArray() ?? []; + + // Deserialize the zones.json file from the wwwroot folder var zonesJson = File.Open("wwwroot/zones.json", FileMode.Open); if (zonesJson is null) diff --git a/start-with-api/Api/Data/NwsManager.cs b/start-with-api/Api/Data/NwsManager.cs index 54da014..4b62a6d 100644 --- a/start-with-api/Api/Data/NwsManager.cs +++ b/start-with-api/Api/Data/NwsManager.cs @@ -13,17 +13,9 @@ public class NwsManager(HttpClient httpClient, IMemoryCache cache) PropertyNameCaseInsensitive = true }; + public async Task GetZonesAsync() { - - - - // To get the live zone data from NWS, uncomment the following code and comment out the return statement below - //var response = await httpClient.GetAsync("https://api.weather.gov/zones?type=forecast"); - //response.EnsureSuccessStatusCode(); - //var content = await response.Content.ReadAsStringAsync(); - //return JsonSerializer.Deserialize(content, options); - return await cache.GetOrCreateAsync("zones", async entry => { if (entry is null) @@ -31,6 +23,18 @@ public class NwsManager(HttpClient httpClient, IMemoryCache cache) entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1); + // To get the live zone data from NWS, uncomment the following code and comment out the return statement below. This is required if you are deploying to ACA + //var response = await httpClient.GetAsync("https://api.weather.gov/zones?type=forecast"); + //response.EnsureSuccessStatusCode(); + //var content = await response.Content.ReadAsStringAsync(); + //var zones = JsonSerializer.Deserialize(content, options); + //return zones?.Features + // ?.Where(f => f.Properties?.ObservationStations?.Count > 0) + // .Select(f => (Zone)f) + // .Distinct() + // .ToArray() ?? []; + + // Deserialize the zones.json file from the wwwroot folder var zonesJson = File.Open("wwwroot/zones.json", FileMode.Open); if (zonesJson is null)