blob: 884240d18f4e244b7ebb08909ac3bff57f987e63 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Microsoft.EntityFrameworkCore;
global using NetTopologySuite.IO.Converters;
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
global using NetTopologySuite.Geometries;
global using Microsoft.AspNetCore.Http.Extensions;
global using Microsoft.AspNetCore.Mvc;
global using NetTopologySuite;
namespace WhatApi;
public partial class Program
{
public static int Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpContextAccessor();
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;
}
}
|