prueba tecnica
This commit is contained in:
51
backend/ProximaContracts/ProximaContracts.API/Program.cs
Normal file
51
backend/ProximaContracts/ProximaContracts.API/Program.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using ProximaContracts.API.Middleware;
|
||||
using ProximaContracts.Application;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("Loopback", p =>
|
||||
p.SetIsOriginAllowed(o => new Uri(o).IsLoopback)
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials());
|
||||
|
||||
options.AddPolicy("ProdDomains", p =>
|
||||
p.WithOrigins(builder.Configuration
|
||||
.GetSection("Cors:AllowedOrigins").Get<string[]>() ?? Array.Empty<string>())
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials());
|
||||
});
|
||||
|
||||
builder.Services.AddApplicationDependencies();
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseCors(app.Environment.IsDevelopment() ? "Loopback" : "ProdDomains");
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user