From a1f0518d0cd123a791adde64f4f11bd8e44276c7 Mon Sep 17 00:00:00 2001 From: ivar Date: Mon, 20 Oct 2025 00:26:34 +0200 Subject: Initial commit --- api/WhatApi/Program.cs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 api/WhatApi/Program.cs (limited to 'api/WhatApi/Program.cs') diff --git a/api/WhatApi/Program.cs b/api/WhatApi/Program.cs new file mode 100644 index 0000000..80d06e8 --- /dev/null +++ b/api/WhatApi/Program.cs @@ -0,0 +1,45 @@ +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.EntityFrameworkCore; +using NetTopologySuite.IO.Converters; + +namespace WhatApi; + +public partial class Program +{ + public static int Main(string[] args) { + var builder = WebApplication.CreateBuilder(args); + + builder.Services.AddDbContextPool(b => { + b.EnableSensitiveDataLogging(); + b.UseNpgsql(builder.Configuration.GetConnectionString("Master"), o => o.UseNetTopologySuite()); + }); + + builder.Services.AddRazorPages(); + builder.Services.AddCors(o => o.AddDefaultPolicy(p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); + builder.Services.AddControllers() + .AddJsonOptions(o => { + o.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + o.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals; + o.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; + o.JsonSerializerOptions.Converters.Add(new GeoJsonConverterFactory()); + }); + + var app = builder.Build(); + +#if DEBUG + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + Seed(db); +#endif + + app.UseRouting(); + app.UseForwardedHeaders(); + app.UseCors(); + app.MapStaticAssets(); + app.MapRazorPages(); + app.MapControllers(); + app.Run(); + return 0; + } +} \ No newline at end of file -- cgit v1.3