Beschikbaarheidspoort blokkeert alleen de API, niet de website en de admin

Een uitgeschakeld CMS gaf een kale 503 op de publieke website en op /admin, omdat de poort elk pad
stopte dat niet op de bypass-lijst stond. Sinds de host website en admin zelf serveert, viel dat verkeer
eronder en kon de admin-app de status niet lezen om de uitgeschakeld-kaart te tonen. Nu worden alleen
paden onder /api/ beoordeeld; alle andere paden gaan door.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 01:35:11 +01:00
co-authored by Claude Sonnet 5.5
parent 190deb0da8
commit 701091f179
7 changed files with 320 additions and 24 deletions
@@ -33,6 +33,13 @@ public class AvailabilityMiddleware
// /health bypasses because it reports infrastructure liveness, which is a different
// question from whether the CMS is switched on: an instance that is deliberately
// disabled is still perfectly healthy, and must not be reported as down.
// Only the API is gated. The public website, the admin files (the SPA with its index.html and assets), the
// 404 page, /sentry-tunnel and /health are not CMS data or actions: a disabled CMS must still show its
// website and let the admin app load, so that the app can read /api/v1/Availability/status (open, see below)
// and show the "CMS disabled" card instead of a bare 503. Before this the gate stopped EVERY path that was not
// on the bypass list, which only went unnoticed while another server (nginx) served the website and the SPA.
private const string GatedPrefix = "/api/";
private static readonly string[] _bypassPrefixes =
[
"/api/v1/Availability/status",
@@ -49,6 +56,13 @@ public class AvailabilityMiddleware
IMasterAvailabilityService masterAvailabilityService)
{
var path = context.Request.Path.Value ?? string.Empty;
if (!path.StartsWith(GatedPrefix, StringComparison.OrdinalIgnoreCase))
{
// Not an API call: nothing to protect, and no reason to look at (or log about) a bearer token either.
await _next(context);
return;
}
if (_bypassPrefixes.Any(p => path.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
{
await _next(context);