From b76b6680979907100848e4f2a846ba442cb8392b Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 16:12:16 +0100 Subject: [PATCH] Addapted to use cors and optimized connection with the frontend --- PyroFetes/Program.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 1251820..e1a719b 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -14,7 +14,20 @@ builder.Services .AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") .AddAuthorization() .AddFastEndpoints() - .SwaggerDocument(); + .SwaggerDocument(options => + { + options.ShortSchemaNames = true; + }) + .AddCors(options => + { + options.AddDefaultPolicy(policyBuilder => + { + policyBuilder + .WithOrigins("http://localhost:4200") + .WithMethods("GET", "POST", "PUT", "DELETE", "PATCH") + .AllowAnyHeader(); + }); + }); // On ajoute ici la configuration de la base de données builder.Services.AddDbContext(); @@ -48,9 +61,15 @@ builder.Services.AddSingleton(mapper); WebApplication app = builder.Build(); app.UseAuthentication() .UseAuthorization() - .UseFastEndpoints() + .UseFastEndpoints(options => + { + options.Endpoints.ShortNames = true; + options.Endpoints.RoutePrefix = "API"; + }) .UseSwaggerGen(); app.UseHttpsRedirection(); +app.UseCors(); + app.Run(); \ No newline at end of file