feat: add application preloader, identity roles, and resilient database initialization with automated seeding
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="/" />
|
||||
<ResourcePreloader />
|
||||
<link rel="stylesheet" href="_content/NexusReader.UI.Shared/app.css" />
|
||||
<link rel="stylesheet" href="NexusReader.Web.styles.css" />
|
||||
<ImportMap />
|
||||
@@ -14,9 +13,35 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app-preloader">
|
||||
<div class="preloader-spinner"></div>
|
||||
<div class="preloader-text">Nexus Reader</div>
|
||||
</div>
|
||||
|
||||
<NexusReader.UI.Shared.Routes @rendermode="InteractiveAuto" />
|
||||
<ReconnectModal />
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
function hidePreloader() {
|
||||
const preloader = document.getElementById('app-preloader');
|
||||
if (preloader) {
|
||||
preloader.classList.add('loaded');
|
||||
// Completely remove from DOM after transition for better accessibility
|
||||
setTimeout(() => preloader.style.display = 'none', 1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete') {
|
||||
hidePreloader();
|
||||
} else {
|
||||
window.addEventListener('load', hidePreloader);
|
||||
}
|
||||
|
||||
// Fallback: If for some reason 'load' doesn't fire (e.g. big assets), hide after 3s anyway
|
||||
setTimeout(hidePreloader, 3000);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ builder.Services.AddAuthentication(options =>
|
||||
});
|
||||
|
||||
builder.Services.AddIdentityApiEndpoints<NexusUser>()
|
||||
.AddRoles<IdentityRole>()
|
||||
.AddEntityFrameworkStores<AppDbContext>();
|
||||
|
||||
builder.Services.ConfigureApplicationCookie(options =>
|
||||
@@ -113,11 +114,38 @@ builder.Services.Configure<IdentityOptions>(options =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Ensure Database is initialized
|
||||
// Ensure Database is initialized and seeded
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<NexusReader.Infrastructure.Persistence.AppDbContext>();
|
||||
await dbContext.Database.MigrateAsync();
|
||||
var services = scope.ServiceProvider;
|
||||
var logger = services.GetRequiredService<ILogger<Program>>();
|
||||
var dbContext = services.GetRequiredService<NexusReader.Infrastructure.Persistence.AppDbContext>();
|
||||
|
||||
int maxRetries = 5;
|
||||
int delayMs = 2000;
|
||||
|
||||
for (int i = 0; i < maxRetries; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Próba połączenia z bazą danych (próba {Attempt}/{MaxRetries})...", i + 1, maxRetries);
|
||||
await dbContext.Database.MigrateAsync();
|
||||
await DbInitializer.SeedAsync(services);
|
||||
logger.LogInformation("Baza danych zainicjowana pomyślnie.");
|
||||
break;
|
||||
}
|
||||
catch (Npgsql.NpgsqlException ex) when (i < maxRetries - 1)
|
||||
{
|
||||
logger.LogWarning("Błąd połączenia z bazą danych: {Message}. Ponowna próba za {Delay}ms...", ex.Message, delayMs);
|
||||
await Task.Delay(delayMs);
|
||||
delayMs *= 2; // Exponential backoff
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogCritical(ex, "Krytyczny błąd podczas inicjalizacji bazy danych.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
"Model": "gemini-2.5-flash-lite",
|
||||
"MaxOutputTokens": 8192
|
||||
}
|
||||
}
|
||||
},
|
||||
"ApiBaseUrl": "http://localhost:5000"
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user