Files

62 lines
1.5 KiB
C#
Raw Permalink Normal View History

2025-12-11 21:38:33 +01:00
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<Microsoft.AspNetCore.Http.Json.JsonOptions>(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<OtaDbContext>(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<OtaDbContext>();
db.Database.EnsureCreated();
}
app.Run();
public partial class Program { }