From e72b4daf51e463b48f83ff200c6f191ded214c84 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Tue, 22 Nov 2022 22:51:37 +0100 Subject: [PATCH] moved httpClient baseAddress to appsettings --- DiscordBot/Program.cs | 2 +- DiscordBot/appsettings.Development.json | 3 +++ DiscordBot/appsettings.json | 5 ++++- Lieb/Program.cs | 2 +- Lieb/appsettings.Development.json | 3 +++ Lieb/appsettings.json | 3 +++ 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 4fcc030..a6149f2 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -40,7 +40,7 @@ namespace DiscordBot builder.Services.AddHttpClient(Constants.HTTP_CLIENT_NAME , httpClient => { - httpClient.BaseAddress = new Uri("https://localhost:7216/"); + httpClient.BaseAddress = new Uri(builder.Configuration["HttpClients:LiebWebsite"]); httpClient.DefaultRequestHeaders.Add( HeaderNames.Accept, "application/vnd.github.v3+json"); diff --git a/DiscordBot/appsettings.Development.json b/DiscordBot/appsettings.Development.json index 0c208ae..1e44d34 100644 --- a/DiscordBot/appsettings.Development.json +++ b/DiscordBot/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "HttpClients": { + "LiebWebsite": "https://localhost:7216/" } } diff --git a/DiscordBot/appsettings.json b/DiscordBot/appsettings.json index 10f68b8..ded9fe9 100644 --- a/DiscordBot/appsettings.json +++ b/DiscordBot/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "HttpClients": { + "LiebWebsite": "lieb-website" + } } diff --git a/Lieb/Program.cs b/Lieb/Program.cs index 776f58d..f5845f7 100644 --- a/Lieb/Program.cs +++ b/Lieb/Program.cs @@ -64,7 +64,7 @@ builder.Services.AddAuthorization(options => builder.Services.AddHttpClient(Constants.HttpClientName , httpClient => { - httpClient.BaseAddress = new Uri("http://localhost:5240/"); + httpClient.BaseAddress = new Uri(builder.Configuration["HttpClients:DiscordBot"]); // using Microsoft.Net.Http.Headers; // The GitHub API requires two headers. diff --git a/Lieb/appsettings.Development.json b/Lieb/appsettings.Development.json index 3770fe7..9b93d6a 100644 --- a/Lieb/appsettings.Development.json +++ b/Lieb/appsettings.Development.json @@ -9,5 +9,8 @@ "AllowedHosts": "*", "ConnectionStrings": { "LiebContext": "Data Source=./Database/mydb.sqlite;" + }, + "HttpClients": { + "DiscordBot": "http://localhost:5240/" } } diff --git a/Lieb/appsettings.json b/Lieb/appsettings.json index f2ad13a..fa5a6f3 100644 --- a/Lieb/appsettings.json +++ b/Lieb/appsettings.json @@ -12,5 +12,8 @@ "AllowedHosts": "*", "ConnectionStrings": { "LiebContext": "Server=liebdb;Database=LiebContext;Uid=root;Pwd=my-secret-pw;" + }, + "HttpClients": { + "DiscordBot": "discord-bot" } } \ No newline at end of file