using Nuuru.Server.Services; namespace Nuuru.Server.Middleware { public class BointsGateMiddleware { private readonly RequestDelegate _next; public BointsGateMiddleware(RequestDelegate next) { _next = next; } public async Task InvokeAsync(HttpContext context, IBointsService bointsService) { var path = context.Request.Path.Value ?? ""; // Allow the status endpoint through always if (path.Equals("/api/boints/status", StringComparison.OrdinalIgnoreCase)) { await _next(context); return; } // Gate all boints and clans endpoints if (path.StartsWith("/api/boints", StringComparison.OrdinalIgnoreCase) || path.StartsWith("/api/clans", StringComparison.OrdinalIgnoreCase)) { if (!await bointsService.IsEnabledAsync()) { context.Response.StatusCode = 404; await context.Response.WriteAsJsonAsync(new { error = "Boints are not enabled." }); return; } } // Gate clans endpoints on separate setting if (path.StartsWith("/api/clans", StringComparison.OrdinalIgnoreCase)) { if (!await bointsService.IsClansEnabledAsync()) { context.Response.StatusCode = 404; await context.Response.WriteAsJsonAsync(new { error = "Clans are not enabled." }); return; } } await _next(context); } } }