init 1.0.0
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Text;
|
||||
using LehrerApp.Api;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.WebHost.UseKestrel(o =>
|
||||
{
|
||||
var port = builder.Configuration.GetValue<int>("Api:Port", 5000);
|
||||
o.ListenAnyIP(port);
|
||||
});
|
||||
|
||||
var secret = builder.Configuration["JWT_SECRET"]
|
||||
?? throw new InvalidOperationException("JWT_SECRET nicht konfiguriert.");
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(o => o.TokenValidationParameters = new()
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret)),
|
||||
ValidateIssuer = false, ValidateAudience = false,
|
||||
ClockSkew = TimeSpan.FromMinutes(5),
|
||||
});
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
var data = builder.Configuration["Api:DataPath"] ?? "./data";
|
||||
builder.Services.AddSingleton<EventStore>(_ => new EventStore(data));
|
||||
builder.Services.AddSingleton<SnapshotStore>(_ => new SnapshotStore(data));
|
||||
builder.Services.AddSingleton<ReadableSnapshotStore>(_ => new ReadableSnapshotStore(data));
|
||||
builder.Services.AddSingleton<PlainEventStore>(sp =>
|
||||
new PlainEventStore(sp.GetRequiredService<EventStore>()));
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapAuthEndpoints(secret);
|
||||
app.MapSyncEndpoints();
|
||||
app.MapSnapshotEndpoints();
|
||||
app.MapReadableSnapshotEndpoints();
|
||||
app.MapPlainSyncEndpoints();
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user