InkForge/InkForge.Api/Program.cs

52 lines
1.3 KiB
C#
Raw Normal View History

2024-02-02 18:46:24 +01:00
using InkForge.Api.Data;
2024-02-07 22:16:59 +01:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
2024-02-02 18:46:24 +01:00
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
2024-02-07 22:16:59 +01:00
builder.Services.AddHttpClient();
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<ApiDbcontext>()
.AddDefaultUI().AddDefaultTokenProviders();
var provider = builder.Configuration.GetValue<string>("DbProvider");
builder.Services.AddDbContext<ApiDbcontext>(options => _ = provider switch
{
"Sqlite" => options.UseSqlite(
builder.Configuration.GetConnectionString("AuthDb"),
x => x.MigrationsAssembly("InkForge.Api.Sqlite")
),
_ => throw new Exception($"Invalid Provider: {provider}")
});
2024-02-02 18:46:24 +01:00
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();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
2024-02-07 22:16:59 +01:00
app.UseStaticFiles();
2024-02-02 18:46:24 +01:00
2024-02-07 22:16:59 +01:00
app.UseRouting();
app.UseAuthentication();
2024-02-02 18:46:24 +01:00
app.UseAuthorization();
app.MapIdentityApi<IdentityUser>();
app.MapControllers();
2024-02-07 22:16:59 +01:00
app.MapRazorPages();
2024-02-02 18:46:24 +01:00
app.Run();