diff --git a/.github/workflows/deploy.prod-env.yml b/.github/workflows/deploy.prod-env.yml index f2fd210..2339d78 100644 --- a/.github/workflows/deploy.prod-env.yml +++ b/.github/workflows/deploy.prod-env.yml @@ -26,5 +26,5 @@ jobs: docker pull git.wohlleben.dev/itob/rbl-news-webapp:latest docker stop rbl-news-webapp docker rm rbl-news-webapp - docker run --init -d --name rbl-news-webapp -p 8000:8080 --restart=always git.wohlleben.dev/itob/rbl-news-webapp:latest + docker run --init -d --name rbl-news-webapp -p 8000:8080 -e RblApiUrl=${{ vars.RBL_PROD_ENV_API_URL }} --restart=always git.wohlleben.dev/itob/rbl-news-webapp:latest docker system prune -af \ No newline at end of file diff --git a/.github/workflows/deploy.test-env.yml b/.github/workflows/deploy.test-env.yml index 4f40f84..9a3990d 100644 --- a/.github/workflows/deploy.test-env.yml +++ b/.github/workflows/deploy.test-env.yml @@ -40,5 +40,5 @@ jobs: docker pull git.wohlleben.dev/itob/rbl-news-webapp:latest docker stop rbl-news-webapp docker rm rbl-news-webapp - docker run --init -d --name rbl-news-webapp -p 8000:8080 --restart=always git.wohlleben.dev/itob/rbl-news-webapp:latest + docker run --init -d --name rbl-news-webapp -p 8000:8080 -e RblApiUrl=${{ vars.RBL_TEST_ENV_API_URL }} --restart=always git.wohlleben.dev/itob/rbl-news-webapp:latest docker system prune -af \ No newline at end of file diff --git a/RBLNews.Maui/MauiProgram.cs b/RBLNews.Maui/MauiProgram.cs index 3eea644..391658f 100644 --- a/RBLNews.Maui/MauiProgram.cs +++ b/RBLNews.Maui/MauiProgram.cs @@ -30,8 +30,21 @@ namespace RBLNews.Maui builder.Services.AddBlazorWebViewDeveloperTools(); builder.Logging.AddDebug(); #endif + + MauiApp app = builder.Build(); - return builder.Build(); + using var serviceScope = app.Services.CreateScope(); + var services = serviceScope.ServiceProvider; + + var environmentVariablesService = services.GetRequiredService(); + string? backendApiUrl = environmentVariablesService.RblApiUrl; + + if (string.IsNullOrEmpty(backendApiUrl)) + { + throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{backendApiUrl}'"); + } + + return app; } } } diff --git a/RBLNews.Shared/Services/EnvironmentVariablesService.cs b/RBLNews.Shared/Services/EnvironmentVariablesService.cs new file mode 100644 index 0000000..ccd8048 --- /dev/null +++ b/RBLNews.Shared/Services/EnvironmentVariablesService.cs @@ -0,0 +1,6 @@ +namespace RBLNews.Shared.Services; + +public class EnvironmentVariablesService +{ + public string? RblApiUrl => Environment.GetEnvironmentVariable("RblApiUrl"); +} \ No newline at end of file diff --git a/RBLNews.Shared/Services/FeedDataService.cs b/RBLNews.Shared/Services/FeedDataService.cs index 6a13540..4262b19 100644 --- a/RBLNews.Shared/Services/FeedDataService.cs +++ b/RBLNews.Shared/Services/FeedDataService.cs @@ -15,15 +15,23 @@ namespace RBLNews.Shared.Services public class FeedDataService : IFeedDataService { + private readonly EnvironmentVariablesService _environmentVariablesService; + private static readonly HttpClient httpClient = new(); public RssVM Feeds { get; private set; } public Action DataChanged { get; set; } + + public FeedDataService(EnvironmentVariablesService environmentVariablesService) + { + this._environmentVariablesService = environmentVariablesService; + } + public async Task LoadFeeds() { - Feeds = await httpClient.GetFromJsonAsync("https://rblnews.de/api/feeds") ?? new RssVM(); + Feeds = await httpClient.GetFromJsonAsync($"{this._environmentVariablesService.RblApiUrl}/api/feeds") ?? new RssVM(); DataChanged.Invoke(); } } diff --git a/RBLNews.Web/Program.cs b/RBLNews.Web/Program.cs index 9ca2574..91f494e 100644 --- a/RBLNews.Web/Program.cs +++ b/RBLNews.Web/Program.cs @@ -5,20 +5,33 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents() - .AddInteractiveServerComponents(); + .AddInteractiveServerComponents(); builder.Services.AddBlazorBootstrap(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Error", createScopeForErrors: true); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Error", createScopeForErrors: true); + + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +using var serviceScope = app.Services.CreateScope(); +IServiceProvider services = serviceScope.ServiceProvider; + +EnvironmentVariablesService environmentVariablesService = services.GetRequiredService(); +string? backendApiUrl = environmentVariablesService.RblApiUrl; + +if (string.IsNullOrEmpty(backendApiUrl)) +{ + throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{backendApiUrl}'"); } app.UseHttpsRedirection(); @@ -27,7 +40,7 @@ app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents() - .AddInteractiveServerRenderMode() - .AddAdditionalAssemblies(typeof(RBLNews.Shared._Imports).Assembly); + .AddInteractiveServerRenderMode() + .AddAdditionalAssemblies(typeof( RBLNews.Shared._Imports ).Assembly); -app.Run(); +app.Run(); \ No newline at end of file