using backend.Auth; using backend.Data; using backend.Devices; using backend.Install; using backend.Pairing; using Microsoft.AspNetCore.DataProtection; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); var keysDir = Environment.GetEnvironmentVariable("DataProtection__KeysDir") ?? "/keys"; if (Directory.Exists(keysDir)) { builder.Services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo(keysDir)) .SetApplicationName("smart-assistant"); } builder.Services.AddDbContext(opt => opt.UseSqlite(builder.Configuration.GetConnectionString("Default"))); builder.Services.AddAppIdentity(); builder.Services.AddAuthorization(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); var app = builder.Build(); using (var scope = app.Services.CreateScope()) { var sp = scope.ServiceProvider; var db = sp.GetRequiredService(); db.Database.Migrate(); await IdentitySetup.SeedRolesAsync(sp); if (db.SystemSettings.Find(1) is null) { db.SystemSettings.Add(new backend.Settings.SystemSettings { Id = 1 }); await db.SaveChangesAsync(); } } app.UseAuthentication(); app.UseAuthorization(); app.MapAuthEndpoints(); app.MapPairingEndpoints(); app.MapDevicesEndpoints(); app.MapInstallEndpoints(); app.MapGet("/health", () => Results.Ok(new { ok = true })); app.Run(); public partial class Program { }