diff options
Diffstat (limited to 'MxApiExtensions/Program.cs')
-rw-r--r-- | MxApiExtensions/Program.cs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/MxApiExtensions/Program.cs b/MxApiExtensions/Program.cs index 11fe114..a219e83 100644 --- a/MxApiExtensions/Program.cs +++ b/MxApiExtensions/Program.cs @@ -1,19 +1,34 @@ +using LibMatrix.Services; using Microsoft.AspNetCore.Http.Timeouts; using MxApiExtensions; +using MxApiExtensions.Services; var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllers(); +builder.Services.AddControllers().AddJsonOptions(options => { + options.JsonSerializerOptions.WriteIndented = true; +}); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); -builder.Services.AddSingleton<CacheConfiguration>(); -builder.Services.AddScoped<Auth>(); +builder.Services.AddSingleton<MxApiExtensionsConfiguration>(); + +builder.Services.AddScoped<AuthenticationService>(); +builder.Services.AddScoped<AuthenticatedHomeserverProviderService>(); + +builder.Services.AddSingleton<TieredStorageService>(x => { + var config = x.GetRequiredService<MxApiExtensionsConfiguration>(); + return new TieredStorageService( + cacheStorageProvider: new FileStorageProvider("/run"), + dataStorageProvider: new FileStorageProvider("/run") + ); +}); +builder.Services.AddRoryLibMatrixServices(); builder.Services.AddRequestTimeouts(x => { x.DefaultPolicy = new RequestTimeoutPolicy { @@ -22,7 +37,7 @@ builder.Services.AddRequestTimeouts(x => { context.Response.StatusCode = 504; context.Response.ContentType = "application/json"; await context.Response.StartAsync(); - await context.Response.WriteAsJsonAsync(new MatrixException { + await context.Response.WriteAsJsonAsync(new MxApiMatrixException { ErrorCode = "M_TIMEOUT", Error = "Request timed out" }.GetAsJson()); @@ -34,8 +49,7 @@ builder.Services.AddRequestTimeouts(x => { var app = builder.Build(); // Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ +if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } |