Files

49 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Server;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
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.");
}
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
app.UseWebAssemblyDebugging();
else
app.UseExceptionHandler("/Error");
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();