Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend/Menu.ApiServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand All @@ -26,6 +27,15 @@ public static TBuilder AddApiServiceDefaults<TBuilder>(this TBuilder builder) wh
// Problem details
builder.Services.AddProblemDetails();

// Response compression (gzip + brotli for JSON API payloads)
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
Comment thread
dgee2 marked this conversation as resolved.
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(["application/problem+json"]);
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});

return builder;
}

Expand All @@ -40,6 +50,7 @@ private static void RegisterDocumentation(SwaggerGenOptions o, string? assemblyN

public static WebApplication MapDefaultApiEndpoints(this WebApplication app)
{
app.UseResponseCompression();
Comment thread
dgee2 marked this conversation as resolved.

app.UseExceptionHandler();

Expand Down
4 changes: 2 additions & 2 deletions backend/MenuApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
// Use CORS middleware before authentication/authorization
app.UseCors("AllowAll");

app.MapDefaultApiEndpoints();

app.UseAuthentication();
app.UseAuthorization();

app.MapDefaultApiEndpoints();

// Configure the APIs
var api = app.MapGroup("/api")
.RequireAuthorization();
Expand Down
Loading