From 456d87f262093f76f1ec502a1052591cb780b3ab Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Sun, 24 Mar 2024 19:20:13 +0100 Subject: [PATCH] Added http debug middleware to trace requests --- .../Http/Middleware/DebugLogMiddleware.cs | 20 +++++++++++++++++++ Moonlight/Moonlight.csproj | 1 - Moonlight/Program.cs | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Moonlight/Core/Http/Middleware/DebugLogMiddleware.cs diff --git a/Moonlight/Core/Http/Middleware/DebugLogMiddleware.cs b/Moonlight/Core/Http/Middleware/DebugLogMiddleware.cs new file mode 100644 index 00000000..3a679271 --- /dev/null +++ b/Moonlight/Core/Http/Middleware/DebugLogMiddleware.cs @@ -0,0 +1,20 @@ +using MoonCore.Helpers; + +namespace Moonlight.Core.Http.Middleware; + +public class DebugLogMiddleware +{ + private RequestDelegate Next; + + public DebugLogMiddleware(RequestDelegate next) + { + Next = next; + } + + public async Task Invoke(HttpContext context) + { + Logger.Debug($"[{context.Request.Method.ToUpper()}] {context.Request.Path}"); + + await Next(context); + } +} \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 007b8aa5..8855c86c 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -51,7 +51,6 @@ - diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index 5770dc14..5aa1ae24 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -4,6 +4,7 @@ using MoonCore.Helpers; using MoonCore.Services; using Moonlight.Core.Configuration; using Moonlight.Core.Database; +using Moonlight.Core.Http.Middleware; using Moonlight.Core.Services; // Create needed storage directories @@ -100,4 +101,9 @@ await pluginService.Initialized(app); app.Services.StartBackgroundServices(); +if (Environment.GetEnvironmentVariables().Contains("DEBUG_HTTP")) +{ + app.UseMiddleware(); +} + app.Run(); \ No newline at end of file