Files
ChronoCCG/Chrono/Server/Program.cs
T
2026-06-25 09:45:21 -04:00

48 lines
1.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using Server;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddTelerikBlazor();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
{
if (!string.IsNullOrEmpty(connectionString)) options.UseNpgsql(connectionString);
});
var app = builder.Build();
// Apply migrations
using (var scope = app.Services.CreateScope())
{
try
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
if (!string.IsNullOrEmpty(connectionString)) db.Database.Migrate();
}
catch (Exception ex)
{
Console.WriteLine(
$"[WARNING] Database migration failed: {ex.Message}. The application will continue without a database connection.");
}
}
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseAntiforgery();
app.MapControllers();
app.MapRazorComponents<Server.Components.App>()
.AddInteractiveServerRenderMode()
.AddAdditionalAssemblies(typeof(Shared.Pages.Home).Assembly);
app.Run();