using Domain.Repository; using Microsoft.EntityFrameworkCore; using Persistence; using Persistence.Repositories; using Services; using Services.Abstractions; using Services.Profiles; var builder = WebApplication.CreateBuilder(args); var configuration = builder.Configuration; var connectionString = builder.Configuration.GetConnectionString("Database"); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Настройка CORS builder.Services.AddCors(options => { options.AddPolicy("AllowFrontend", policy => { policy.WithOrigins("http://localhost:3000") .AllowAnyHeader() .AllowAnyMethod(); }); }); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddDbContext( options => { options.UseNpgsql(connectionString); }); builder.Services.AddAutoMapper(typeof(MappingProfile)); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); // Разрешаем CORS для фронтенда app.UseCors("AllowFrontend"); app.UseAuthorization(); app.MapControllers(); app.Run();