From ab2478ab67d208a59df8ca50dc45ce7d4b99d173 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 23 May 2021 21:36:12 +0100 Subject: [PATCH] feat(*): Perform initial setup This involves setting up the config file and the httpclient. --- CityFinder/CityFinder.csproj | 18 ++++++++++++++++++ CityFinder/Program.cs | 19 +++++++++++++++++++ CityFinder/appsettings.json | 3 +++ 3 files changed, 40 insertions(+) create mode 100644 CityFinder/appsettings.json diff --git a/CityFinder/CityFinder.csproj b/CityFinder/CityFinder.csproj index 5d69b21..9689360 100644 --- a/CityFinder/CityFinder.csproj +++ b/CityFinder/CityFinder.csproj @@ -5,6 +5,24 @@ net5.0 + + + + + + + PreserveNewest + + + + + + + + + + + PreserveNewest diff --git a/CityFinder/Program.cs b/CityFinder/Program.cs index e314632..7530f5f 100644 --- a/CityFinder/Program.cs +++ b/CityFinder/Program.cs @@ -29,7 +29,26 @@ namespace CityFinder { internal class Program { + private static readonly HttpClient client = new HttpClient(); + private static IConfigurationRoot config; private static async Task Main(string[] args) { + InitialSetup(); + + /// + /// This method sets up the json config file and sets the user-agent header on the HttpClient. + /// + private static void InitialSetup() + { + // Set up handling json config files + IConfigurationBuilder builder = new ConfigurationBuilder() + .AddJsonFile($"appsettings.json", true, true) + .AddEnvironmentVariables(); + config = builder.Build(); + + // Set default user-agent on the HttpClient to enable using the Google API from code + client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"); } + } + } } diff --git a/CityFinder/appsettings.json b/CityFinder/appsettings.json new file mode 100644 index 0000000..b72dcc6 --- /dev/null +++ b/CityFinder/appsettings.json @@ -0,0 +1,3 @@ +{ + "GoogleMapsGeocodeApiKey": "your-key-goes-here" +}