Foxchat.NET/Foxchat.Identity/Program.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2024-05-11 15:26:47 +02:00
using Newtonsoft.Json.Serialization;
using Serilog;
using Foxchat.Core;
using Foxchat.Identity;
using Foxchat.Identity.Database;
using Foxchat.Identity.Services;
var builder = WebApplication.CreateBuilder(args);
var config = builder.AddConfiguration<InstanceConfig>("identity.ini");
2024-05-19 17:20:45 +02:00
builder.AddSerilog(config.LogEventLevel);
2024-05-11 15:26:47 +02:00
await BuildInfo.ReadBuildInfo();
Log.Information("Starting Foxchat.Identity {Version} ({Hash})", BuildInfo.Version, BuildInfo.Hash);
builder.Services
.AddControllers()
.AddNewtonsoftJson(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
});
builder.Services
.AddCoreServices<IdentityContext>()
.AddScoped<ChatInstanceResolverService>()
.AddEndpointsApiExplorer()
.AddSwaggerGen();
var app = builder.Build();
app.UseSerilogRequestLogging();
app.UseRouting();
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
using (var scope = app.Services.CreateScope())
using (var context = scope.ServiceProvider.GetRequiredService<IdentityContext>())
{
Log.Information("Initializing instance keypair...");
if (await context.InitializeInstanceAsync())
{
Log.Information("Initialized instance keypair");
}
}
app.Urls.Clear();
app.Urls.Add(config.Address);
app.Run();