build script for maui apk adjusted 2 #2

Open
itob wants to merge 29 commits from development into master
6 changed files with 51 additions and 11 deletions
Showing only changes of commit 5076367282 - Show all commits

View File

@ -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

View File

@ -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

View File

@ -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<EnvironmentVariablesService>();
string? backendApiUrl = environmentVariablesService.RblApiUrl;
if (string.IsNullOrEmpty(backendApiUrl))
{
throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{backendApiUrl}'");
}
return app;
}
}
}

View File

@ -0,0 +1,6 @@
namespace RBLNews.Shared.Services;
public class EnvironmentVariablesService
{
public string? RblApiUrl => Environment.GetEnvironmentVariable("RblApiUrl");
}

View File

@ -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<RssVM>("https://rblnews.de/api/feeds") ?? new RssVM();
Feeds = await httpClient.GetFromJsonAsync<RssVM>($"{this._environmentVariablesService.RblApiUrl}/api/feeds") ?? new RssVM();
DataChanged.Invoke();
}
}

View File

@ -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<IFeedDataService, FeedDataService>();
builder.Services.AddSingleton<AppLifecycleService>();
builder.Services.AddSingleton<EnvironmentVariablesService>();
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<EnvironmentVariablesService>();
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<App>()
.AddInteractiveServerRenderMode()
.AddAdditionalAssemblies(typeof(RBLNews.Shared._Imports).Assembly);
.AddInteractiveServerRenderMode()
.AddAdditionalAssemblies(typeof( RBLNews.Shared._Imports ).Assembly);
app.Run();
app.Run();