summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Program.cs
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-20 00:26:34 +0200
committerivar <i@oiee.no>2025-10-20 00:26:34 +0200
commita1f0518d0cd123a791adde64f4f11bd8e44276c7 (patch)
tree675a7dff8262eea877ec800ff1efe9b92f5d7e7d /api/WhatApi/Program.cs
downloadwhat-a1f0518d0cd123a791adde64f4f11bd8e44276c7.tar.xz
what-a1f0518d0cd123a791adde64f4f11bd8e44276c7.zip
Initial commit
Diffstat (limited to 'api/WhatApi/Program.cs')
-rw-r--r--api/WhatApi/Program.cs45
1 files changed, 45 insertions, 0 deletions
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<Database>(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<Database>();
+ 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