diff options
Diffstat (limited to 'api/WhatApi/Program.cs')
| -rw-r--r-- | api/WhatApi/Program.cs | 45 |
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 |
