using Microsoft.EntityFrameworkCore; using OtaFleet.Api.Data; using OtaFleet.Api.Endpoints; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddOpenApi(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Fix object cycle depth for JSON serialization builder.Services.Configure(options => { options.SerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; }); // Helper to disable CORS for local dev builder.Services.AddCors(options => { options.AddDefaultPolicy(policy => { policy.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); builder.Services.AddDbContext(options => options.UseSqlite("Data Source=ota.db")); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); app.UseSwagger(); app.UseSwaggerUI(); } app.UseCors(); // app.UseHttpsRedirection(); // Map endpoints app.MapVehicleEndpoints(); app.MapAdminEndpoints(); // Create uploads directory if not exists Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "uploads")); // Ensure DB is created using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); db.Database.EnsureCreated(); } app.Run(); public partial class Program { }