blob: 3e9cb80b029c257b83065dbdb76c7869fc36aee6 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
|
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using ArcaneLibs.Extensions;
using LibMatrix.Extensions;
using LibMatrix.Federation;
using LibMatrix.FederationTest.Services;
using LibMatrix.Services;
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers()
.ConfigureApiBehaviorOptions(options => {
options.InvalidModelStateResponseFactory = context => {
var problemDetails = new ValidationProblemDetails(context.ModelState) {
Status = StatusCodes.Status400BadRequest,
Title = "One or more validation errors occurred.",
Detail = "See the errors property for more details.",
Instance = context.HttpContext.Request.Path
};
Console.WriteLine("Model validation failed: " + problemDetails.ToJson());
return new BadRequestObjectResult(problemDetails) {
ContentTypes = { "application/problem+json", "application/problem+xml" }
};
};
})
.AddJsonOptions(options => {
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.WriteIndented = true;
// options.JsonSerializerOptions.DefaultBufferSize = ;
}).AddMvcOptions(o => { o.SuppressOutputFormatterBuffering = true; });
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddHttpLogging(options => {
options.LoggingFields = Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.All;
options.RequestHeaders.Add("X-Forwarded-Proto");
options.RequestHeaders.Add("X-Forwarded-Host");
options.RequestHeaders.Add("X-Forwarded-Port");
});
builder.Services.AddRazorPages();
builder.Services.AddHttpContextAccessor();
builder.Services.AddRoryLibMatrixServices();
builder.Services.AddSingleton<FederationTestConfiguration>();
builder.Services.AddSingleton<FederationKeyStore>();
builder.Services.AddScoped<ServerAuthService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (true || app.Environment.IsDevelopment()) {
app.MapOpenApi();
}
// app.UseAuthorization();
app.MapControllers();
app.MapRazorPages();
// app.UseHttpLogging();
app.Run();
|