Added http debug middleware to trace requests

This commit is contained in:
Marcel Baumgartner 2024-03-24 19:20:13 +01:00
parent e47a4c29f7
commit 456d87f262
3 changed files with 26 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -51,7 +51,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="Core\Database\Migrations\" /> <Folder Include="Core\Database\Migrations\" />
<Folder Include="Core\Http\Middleware\" />
<Folder Include="Core\Http\Requests\" /> <Folder Include="Core\Http\Requests\" />
<Folder Include="Core\Http\Resources\" /> <Folder Include="Core\Http\Resources\" />
<Folder Include="Core\UI\Components\Forms\" /> <Folder Include="Core\UI\Components\Forms\" />

View file

@ -4,6 +4,7 @@ using MoonCore.Helpers;
using MoonCore.Services; using MoonCore.Services;
using Moonlight.Core.Configuration; using Moonlight.Core.Configuration;
using Moonlight.Core.Database; using Moonlight.Core.Database;
using Moonlight.Core.Http.Middleware;
using Moonlight.Core.Services; using Moonlight.Core.Services;
// Create needed storage directories // Create needed storage directories
@ -100,4 +101,9 @@ await pluginService.Initialized(app);
app.Services.StartBackgroundServices<Program>(); app.Services.StartBackgroundServices<Program>();
if (Environment.GetEnvironmentVariables().Contains("DEBUG_HTTP"))
{
app.UseMiddleware<DebugLogMiddleware>();
}
app.Run(); app.Run();