using DbFirst.API.Middleware; using DbFirst.Application; using DbFirst.Application.Repositories; using DbFirst.Domain; using DbFirst.Infrastructure; using DbFirst.Infrastructure.Repositories; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // TODO: allow listed origins configured in appsettings.json // In any case, dont let them to free to use without cors. if there is no origin specified, block all. // In development you can keep it easy. builder.Services.AddCors(options => { options.AddDefaultPolicy(policy => { if (builder.Environment.IsDevelopment()) { policy.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); } else { var origins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get() ?? Array.Empty(); if (origins.Length > 0) { policy.WithOrigins(origins) .AllowAnyHeader() .AllowAnyMethod(); } // if no origins configured, deny all by leaving policy without allowances } }); }); builder.Services.AddInfrastructure(builder.Configuration); builder.Services.AddApplication(); builder.Services.AddScoped(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseMiddleware(); app.UseHttpsRedirection(); app.UseCors(); app.UseAuthorization(); app.MapControllers(); app.Run();