using Microsoft.EntityFrameworkCore; using EonaCat.LogStack.Status.Data; using EonaCat.LogStack.Status.Services; // This file is part of the EonaCat project(s) which is released under the Apache License. // See the LICENSE file or go to https://EonaCat.com/License for full license details. var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddSession(options => { options.IdleTimeout = TimeSpan.FromHours(8); options.Cookie.HttpOnly = true; options.Cookie.IsEssential = true; }); var dbPath = Path.Combine(builder.Environment.ContentRootPath, "EonaCat.LogStack.Status.db"); builder.Services.AddDbContextFactory(options => options.UseSqlite($"Data Source={dbPath}")); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHostedService(); builder.Services.AddControllers(); var app = builder.Build(); // Ensure database is created and apply any pending migrations using (var scope = app.Services.CreateScope()) { var database = scope.ServiceProvider.GetRequiredService>().CreateDbContext(); database.Database.EnsureCreated(); } app.UseStaticFiles(); app.UseRouting(); app.UseSession(); app.MapRazorPages(); app.MapControllers(); app.Run();