dot-net/Program.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2025-01-11 23:30:12 +00:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
2025-01-11 21:29:43 +00:00
using Scalar.AspNetCore;
2025-01-11 23:30:12 +00:00
using Trazo.Model;
2025-01-11 21:29:43 +00:00
2025-01-11 21:20:05 +00:00
var builder = WebApplication.CreateBuilder(args);
2025-01-11 23:30:12 +00:00
builder.Services.AddControllers();
2025-01-11 21:20:05 +00:00
// Add services to the container.
2025-01-11 23:30:12 +00:00
builder.Services.AddAuthorization();
builder.Services.AddIdentity<User, IdentityRole<Guid>>(options =>
{
options.SignIn.RequireConfirmedAccount = true;
options.Password.RequiredLength = 8;
})
2025-01-11 23:30:12 +00:00
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager();
2025-01-11 23:30:12 +00:00
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("Database")));
2025-01-11 21:20:05 +00:00
// CORS
builder.Services.AddCors(options =>
{
options.AddPolicy("ApiPolicy", builder =>
{
builder.WithOrigins("http://localhost")
.AllowAnyMethod()
.AllowAnyHeader();
});
});
2025-01-11 21:20:05 +00:00
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
2025-01-12 21:09:25 +00:00
builder.Services.AddSwaggerGen(options =>
{
options.SupportNonNullableReferenceTypes();
}
);
2025-01-11 21:20:05 +00:00
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
2025-01-11 21:29:43 +00:00
app.UseSwagger(options =>
{
options.RouteTemplate = "openapi/{documentName}.json";
});
app.MapScalarApiReference();
2025-01-11 21:20:05 +00:00
}
app.UseCors("ApiPolicy");
app.UseAuthentication();
2025-01-11 21:20:05 +00:00
app.UseAuthorization();
/*app.MapIdentityApi<User>();*/
2025-01-11 21:20:05 +00:00
app.MapControllers();
app.Run();