diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs index 0a38399..417195c 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs @@ -8,10 +8,16 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. +// CORS setup to allow requests from any origin. +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.AddEndpointsApiExplorer(); //builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -28,7 +34,6 @@ builder.Services.AddDbContext(option => var app = builder.Build(); - // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { @@ -36,8 +41,11 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } -app.UseAuthorization(); +// Enable CORS, authentication, and authorization middleware. +app.UseCors("DamageAppCorsPolicy"); +app.UseAuthorization(); +// Map controllers to their respective routes. app.MapControllers(); app.Run(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs index 4fd2e59..6aa5ed1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs @@ -8,12 +8,18 @@ using System.Reflection; var builder = WebApplication.CreateBuilder(args); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); //builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -45,6 +51,8 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } +// Enable CORS, authentication, and authorization middleware. +app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.UseHttpsRedirection(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs index f28dd76..a2ec7ef 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs @@ -6,6 +6,11 @@ using System.Reflection; var builder = WebApplication.CreateBuilder(args); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + // Add services to the container. builder.Services.AddControllers(); @@ -36,6 +41,9 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } + +// Enable CORS, authentication, and authorization middleware. +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..b8548ff 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs @@ -6,12 +6,18 @@ using System.Reflection; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + + +// Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -//builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -43,6 +49,9 @@ if (app.Environment.IsDevelopment()) } } +// Enable CORS, authentication, and authorization middleware. +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..a96e13f 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs @@ -5,13 +5,18 @@ using Microsoft.EntityFrameworkCore; using System.Reflection; var builder = WebApplication.CreateBuilder(args); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + // Add services to the container. - +// Add controller services and API Explorer for endpoint discovery. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -//builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -44,6 +49,9 @@ if (app.Environment.IsDevelopment()) } } +// Enable CORS, authentication, and authorization middleware. +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..2eedaff 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs @@ -15,8 +15,14 @@ builder.Services.AddControllers(); builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); + +// Add controller services and API Explorer for endpoint discovery. builder.Services.AddEndpointsApiExplorer(); -//builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -44,6 +50,8 @@ if (app.Environment.IsDevelopment()) } } +// Enable CORS, authentication, and authorization middleware. +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..972ccce 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs @@ -16,6 +16,10 @@ const int intervalForCircuitBraker = 5; //5 seconds // Add services to the container. builder.Services.AddControllers(); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddScoped(); @@ -36,6 +40,7 @@ builder.Services.AddHttpClient(). builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Services.AddEndpointsApiExplorer(); //builder.Services.AddSwaggerGen(); +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -56,6 +61,8 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } +// Enable CORS, authentication, and authorization middleware. +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..c6a58a3 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs @@ -10,7 +10,11 @@ using System.Reflection; var builder = WebApplication.CreateBuilder(args); // Add services to the container. + +// Retrieve the security key for JWT token validation. var authkey = builder.Configuration.GetValue("JwtSettings:securitykey"); + +// Configure JWT authentication and validation. builder.Services.AddAuthentication(item => { item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -29,12 +33,18 @@ builder.Services.AddAuthentication(item => }; }); +// CORS setup to allow requests from any origin. +builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => { + build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); +})); +// Add controller services and API Explorer for endpoint discovery. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Services.AddEndpointsApiExplorer(); -//builder.Services.AddSwaggerGen(); + +// Add Swagger/OpenAPI documentation support. builder.Services.AddSwaggerGen(c => { // Include XML comments from your assembly @@ -42,10 +52,13 @@ builder.Services.AddSwaggerGen(c => var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); + +// Configure the database context for SurveysDbContext using SQL Server. builder.Services.AddDbContext(option => { option.UseSqlServer("SurveyConnection"); }); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -53,7 +66,7 @@ if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); - + // Seed initial data in the database when in development mode using (var serviceScope = app.Services.CreateScope()) { var services = serviceScope.ServiceProvider; @@ -61,10 +74,11 @@ if (app.Environment.IsDevelopment()) surveyProvider.seedData(); } } - +// Enable CORS, authentication, and authorization middleware. +app.UseCors("DamageAppCorsPolicy"); app.UseAuthentication(); app.UseAuthorization(); - +// Map controllers to their respective routes. app.MapControllers(); app.Run();