67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using Newtonsoft.Json.Serialization;
|
|
using Serilog;
|
|
using Foxchat.Core;
|
|
using Foxchat.Core.Extensions;
|
|
using Foxchat.Identity;
|
|
using Foxchat.Identity.Database;
|
|
using Foxchat.Identity.Services;
|
|
using Foxchat.Identity.Extensions;
|
|
using Newtonsoft.Json;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var config = builder.AddConfiguration<InstanceConfig>("identity.ini");
|
|
|
|
builder.AddSerilog();
|
|
|
|
await BuildInfo.ReadBuildInfo();
|
|
Log.Information("Starting Foxchat.Identity {Version} ({Hash})", BuildInfo.Version, BuildInfo.Hash);
|
|
|
|
// Set the default converter to snake case as we use it in a couple places.
|
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
|
{
|
|
ContractResolver = new DefaultContractResolver
|
|
{
|
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
|
}
|
|
};
|
|
|
|
builder.Services
|
|
.AddControllers()
|
|
.AddNewtonsoftJson(options =>
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver
|
|
{
|
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
|
});
|
|
|
|
builder.Services
|
|
.AddCoreServices<IdentityContext>()
|
|
.AddScoped<ChatInstanceResolverService>()
|
|
.AddCustomMiddleware()
|
|
.AddEndpointsApiExplorer()
|
|
.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseSerilogRequestLogging();
|
|
app.UseRouting();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
app.UseCors();
|
|
app.UseCustomMiddleware();
|
|
app.MapControllers();
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
await 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();
|