From 43d573c8079ee28cdcf5bb2372bcecbd0f03d07d Mon Sep 17 00:00:00 2001 From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:30:35 +0100 Subject: [PATCH] Ignore API Key when accessing healthcheck endpoint --- 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 +}