Files
BeReadyBackend/BeReadyBackend/Program.cs
T
2026-03-01 14:22:44 +01:00

79 lines
2.4 KiB
C#

using AutoMapper;
using AutoMapper.EquivalencyExpression;
using BeReadyBackend;
using BeReadyBackend.Hubs;
using BeReadyBackend.MappingProfiles;
using FastEndpoints;
using FastEndpoints.Swagger;
using FastEndpoints.Security;
using Microsoft.Net.Http.Headers;
using BeReadyBackend.Repositories;
using BeReadyBackend.Services;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
builder.Services
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
.AddAuthorization()
.AddFastEndpoints()
.AddCors(options =>
{
options.AddDefaultPolicy(policyBuilder =>
{
policyBuilder
.WithOrigins("http://localhost:4200")
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
.AllowAnyHeader()
.WithExposedHeaders(HeaderNames.ContentDisposition);
});
})
.SwaggerDocument(options => { options.ShortSchemaNames = true; });
builder.Services.AddDbContext<BeReadyDbContext>();
builder.Services.AddScoped<AchievementsRepository>();
builder.Services.AddScoped<DesignationsRepository>();
builder.Services.AddScoped<GroupsRepository>();
builder.Services.AddScoped<MessagesRepository>();
builder.Services.AddScoped<RandomChallengesRepository>();
builder.Services.AddScoped<UserAchievementsRepository>();
builder.Services.AddScoped<UserFriendsRepository>();
builder.Services.AddScoped<UserGroupsRepository>();
builder.Services.AddScoped<UserRandomChallengesRepository>();
builder.Services.AddScoped<UsersRepository>();
builder.Services.AddSignalR();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<UserService>();
MapperConfiguration mappingConfig = new(mc =>
{
mc.AddCollectionMappers();
mc.AddProfile(new DtoToEntityMappings());
mc.AddProfile(new EntityToDtoMappings());
}, new LoggerFactory());
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
builder.Services.AddSingleton(mapper);
WebApplication app = builder.Build();
app.UseAuthentication()
.UseAuthorization()
.UseFastEndpoints(options =>
{
options.Endpoints.ShortNames = true;
options.Endpoints.RoutePrefix = "API";
})
.UseSwaggerGen();
app.MapHub<GroupHub>("/groupHub");
// app.UseHttpsRedirection();
// app.UseCors();
app.Run();