using HA_Shopping_List.Server.Components; using HA_Shopping_List.Server.Data; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); // Blazor Server interactif builder.Services.AddRazorComponents() .AddInteractiveServerComponents(options => options.DetailedErrors = true); // Persistance dans /data (Home Assistant) ou dans le dossier local en Dev var dbFolder = Directory.Exists("/data") ? "/data" : AppContext.BaseDirectory; Directory.CreateDirectory(dbFolder); var dbPath = Path.Combine(dbFolder, "shopping.db"); builder.Services.AddDbContextFactory(options => options.UseSqlite($"Data Source={dbPath}")); var app = builder.Build(); // Création automatique de la base SQLite au démarrage using (var scope = app.Services.CreateScope()) { var factory = scope.ServiceProvider.GetRequiredService>(); using var db = factory.CreateDbContext(); db.Database.EnsureCreated(); } #if DEBUG app.Use(async (context, next) => { context.Response.Headers.Append("Permissions-Policy", "unload=(self)"); await next(); }); #endif // Gestion du préfixe dynamique Ingress de Home Assistant app.Use(async (context, next) => { if (context.Request.Headers.TryGetValue("X-Ingress-Path", out var ingressPath)) { context.Request.PathBase = ingressPath.ToString(); } await next(); }); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", createScopeForErrors: true); } app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); // Port Ingress standard app.Run("http://0.0.0.0:8099");