52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
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();
|