2024-05-28 15:29:18 +02:00
|
|
|
using Foxnouns.Backend;
|
2024-05-27 15:53:54 +02:00
|
|
|
using Foxnouns.Backend.Database;
|
|
|
|
using Serilog;
|
|
|
|
using Foxnouns.Backend.Extensions;
|
2024-05-28 15:29:18 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-27 15:53:54 +02:00
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
var config = builder.AddConfiguration();
|
|
|
|
|
|
|
|
builder.AddSerilog(config.LogEventLevel);
|
|
|
|
|
|
|
|
builder.Services
|
|
|
|
.AddControllers()
|
|
|
|
.AddNewtonsoftJson(options =>
|
|
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver
|
|
|
|
{
|
|
|
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
2024-05-28 15:29:18 +02:00
|
|
|
})
|
|
|
|
.ConfigureApiBehaviorOptions(options =>
|
|
|
|
{
|
|
|
|
options.InvalidModelStateResponseFactory = actionContext => new BadRequestObjectResult(
|
|
|
|
new ApiError.BadRequest("Bad request", actionContext.ModelState).ToJson()
|
|
|
|
);
|
|
|
|
});
|
2024-05-27 15:53:54 +02:00
|
|
|
|
|
|
|
builder.Services
|
|
|
|
.AddDbContext<DatabaseContext>()
|
2024-05-28 15:29:18 +02:00
|
|
|
.AddCustomServices()
|
|
|
|
.AddCustomMiddleware()
|
2024-05-27 15:53:54 +02:00
|
|
|
.AddEndpointsApiExplorer()
|
|
|
|
.AddSwaggerGen();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
2024-05-28 15:29:18 +02:00
|
|
|
await app.Initialize(args);
|
|
|
|
|
2024-05-27 15:53:54 +02:00
|
|
|
app.UseSerilogRequestLogging();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
app.UseCors();
|
2024-05-28 15:29:18 +02:00
|
|
|
app.UseCustomMiddleware();
|
2024-05-27 15:53:54 +02:00
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
app.Urls.Clear();
|
|
|
|
app.Urls.Add(config.Address);
|
|
|
|
|
|
|
|
app.Run();
|
|
|
|
|
2024-05-28 15:29:18 +02:00
|
|
|
Log.CloseAndFlush();
|