Foxchat.NET/Foxchat.Chat/Program.cs

53 lines
1.3 KiB
C#

using Newtonsoft.Json.Serialization;
using Serilog;
using Foxchat.Core;
using Foxchat.Chat;
using Foxchat.Chat.Database;
var builder = WebApplication.CreateBuilder(args);
var config = builder.AddConfiguration<InstanceConfig>("chat.ini");
builder.AddSerilog(config.LogEventLevel);
await BuildInfo.ReadBuildInfo();
Log.Information("Starting Foxchat.Chat {Version} ({Hash})", BuildInfo.Version, BuildInfo.Hash);
builder.Services
.AddControllers()
.AddNewtonsoftJson(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
});
builder.Services
.AddCoreServices<ChatContext>()
.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<ChatContext>())
{
Log.Information("Initializing instance keypair...");
if (await context.InitializeInstanceAsync())
{
Log.Information("Initialized instance keypair");
}
}
app.Urls.Clear();
app.Urls.Add(config.Address);
app.Run();