From 17df019d55caf8d9712af0022ce0cf3b8517fcaf Mon Sep 17 00:00:00 2001 From: Reginald Cherenfant Jasmin Date: Fri, 10 Nov 2023 13:07:50 -0500 Subject: [PATCH] Adding CORS policy to all micro-services --- DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs | 6 +++++- .../DamageAssesment.Api.Attachments/Program.cs | 6 ++++-- DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs | 5 ++++- DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs | 6 ++++-- DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs | 5 ++++- DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs | 5 ++++- DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs | 4 ++++ DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs | 6 ++++++ 8 files changed, 35 insertions(+), 8 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs index 0a38399..1069795 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs @@ -26,6 +26,10 @@ builder.Services.AddDbContext(option => option.UseSqlServer("AnswerConnection"); }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + var app = builder.Build(); @@ -35,7 +39,7 @@ if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs index 4fd2e59..3c5a440 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs @@ -35,6 +35,9 @@ builder.Services.Configure(o => o.MultipartBodyLengthLimit = int.MaxValue; o.MemoryBufferThreshold = int.MaxValue; }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); @@ -44,10 +47,9 @@ if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.UseHttpsRedirection(); - app.MapControllers(); app.UseStaticFiles(); app.Run(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs index f28dd76..5dcf1ed 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs @@ -27,6 +27,9 @@ builder.Services.AddDbContext(option => { option.UseSqlServer("DoculinConnection"); }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -35,7 +38,7 @@ if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs index 7d61871..c93eb2e 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs @@ -26,7 +26,9 @@ builder.Services.AddDbContext(option => { option.UseSqlServer("EmployeeConnection"); }); - +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -42,7 +44,7 @@ if (app.Environment.IsDevelopment()) employeesProvider.SeedData(); } } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs index f8136bd..22457e4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs @@ -26,6 +26,9 @@ builder.Services.AddDbContext(option => { option.UseSqlServer("LocationConnection"); }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -43,7 +46,7 @@ if (app.Environment.IsDevelopment()) regionProvider.SeedData(); } } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs index c47a38d..203f267 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs @@ -28,6 +28,9 @@ builder.Services.AddDbContext(option => { option.UseSqlServer("QuestionConnection"); }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -43,7 +46,7 @@ if (app.Environment.IsDevelopment()) questionProvider.SeedData(); } } - +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs index 8b25674..d09a9d0 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs @@ -47,6 +47,9 @@ builder.Services.AddDbContext(option => { option.UseSqlServer("ResponsesConnection"); }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -56,6 +59,7 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs index 178b5fd..0bbba02 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs @@ -29,6 +29,11 @@ builder.Services.AddAuthentication(item => }; }); +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddScoped(); @@ -62,6 +67,7 @@ if (app.Environment.IsDevelopment()) } } +app.UseCors("DamageAppCorsPolicy"); app.UseAuthentication(); app.UseAuthorization();