From 58ee71caaeb6ba4bdd138660de69626a9a0bc440 Mon Sep 17 00:00:00 2001 From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:43:12 +0100 Subject: [PATCH] Ignore API Key when accessing healthcheck endpoint (#534) --- TramsDataApi/Middleware/ApiKeyMiddleware.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TramsDataApi/Middleware/ApiKeyMiddleware.cs b/TramsDataApi/Middleware/ApiKeyMiddleware.cs index d0f0778d5..04364916c 100644 --- a/TramsDataApi/Middleware/ApiKeyMiddleware.cs +++ b/TramsDataApi/Middleware/ApiKeyMiddleware.cs @@ -20,6 +20,12 @@ public ApiKeyMiddleware(RequestDelegate next, ILogger logger) } public async Task InvokeAsync(HttpContext context, IUseCase apiKeyService) { + // Bypass API Key requirement for health check route + if (context.Request.Path == "/HealthCheck") { + await _next(context); + return; + } + if (!context.Request.Headers.TryGetValue(APIKEYNAME, out var extractedApiKey)) { context.Response.StatusCode = 401; @@ -43,4 +49,4 @@ public async Task InvokeAsync(HttpContext context, IUseCase api } } } -} \ No newline at end of file +}