using FozFc.Api.Api; using FozFc.Api.Api.Endpoints; using FozFc.Api.Api.Middleware; using FozFc.Api.Application.Seeding; using FozFc.Api.Configuration; using FozFc.Api.Infrastructure.Storage; using Microsoft.Extensions.FileProviders; var options = AppOptions.FromEnvironment(); var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseUrls($"http://0.0.0.0:{options.Port}"); builder.Services .AddFozFcServices(options) .AddFozFcAuth(options) .AddFozFcCors(options); var app = builder.Build(); // --- Middleware pipeline --- app.UseMiddleware(); app.UseCors(); app.UseAuthentication(); app.UseAuthorization(); // Serve uploaded files from the local uploads directory. var uploadsPath = Path.Combine(Directory.GetCurrentDirectory(), LocalFileStorage.UploadsDirectory); Directory.CreateDirectory(uploadsPath); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(uploadsPath), RequestPath = "/uploads", }); // --- Endpoints --- app.MapHealthEndpoints(); app.MapAuthEndpoints(); app.MapContactEndpoints(); app.MapUploadEndpoints(); app.MapZerozeroEndpoints(); app.MapCrudEndpoints(); // --- Seed baseline data --- using (var scope = app.Services.CreateScope()) { var seeder = scope.ServiceProvider.GetRequiredService(); await seeder.SeedAsync(); } app.Logger.LogInformation("FC Foz backend listening on port {Port}", options.Port); app.Run();