Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions DebugProbe.AspNetCore/Extensions/DebugProbeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Net.Http.Json;
using System.Net.Http.Json;
using DebugProbe.AspNetCore.Handlers;
using DebugProbe.AspNetCore.Internal.Compare;
using DebugProbe.AspNetCore.Internal.Rendering;
Expand Down Expand Up @@ -90,9 +90,11 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac

if (app is WebApplication webApp)
{
var prefix = options.RoutePrefix;

if (ShouldMapUiEndpoints(environment, options))
{
RequireDebugAuthorization(webApp.MapGet("/debug", async (HttpContext ctx, DebugEntryStore store) =>
RequireDebugAuthorization(webApp.MapGet(prefix, async (HttpContext ctx, DebugEntryStore store) =>
{
var items = store.GetAll()
.OrderByDescending(x => x.Timestamp)
Expand All @@ -105,7 +107,7 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.MapGet("/debug/{id}", async (HttpContext ctx, string id, DebugEntryStore store) =>
RequireDebugAuthorization(webApp.MapGet($"{prefix}/{{id}}", async (HttpContext ctx, string id, DebugEntryStore store) =>
{
var item = store.Get(id);

Expand Down Expand Up @@ -139,7 +141,7 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.MapGet("/debug/js/{file}", (string file) =>
RequireDebugAuthorization(webApp.MapGet($"{prefix}/js/{{file}}", (string file) =>
{
if (!EmbeddedResources.JavaScript.TryGetValue(file, out var content))
{
Expand All @@ -150,24 +152,24 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.MapPost("/debug/clear", (DebugEntryStore store) =>
RequireDebugAuthorization(webApp.MapPost($"{prefix}/clear", (DebugEntryStore store) =>
{
store.Clear();

return Results.Ok();

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.Map("/debug/logo.png", ctx =>
RequireDebugAuthorization(webApp.Map($"{prefix}/logo.png", ctx =>
EmbeddedAssetWriter.WriteEmbeddedAsset(ctx, "DebugProbe.AspNetCore.Assets.images.debugprobe_logo_white_transparent.png", "image/png")
).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.Map("/debug/favicon.ico", ctx =>
RequireDebugAuthorization(webApp.Map($"{prefix}/favicon.ico", ctx =>
EmbeddedAssetWriter.WriteEmbeddedAsset(ctx, "DebugProbe.AspNetCore.Assets.images.debugprobe_favicon.ico", "image/x-icon")
).ExcludeFromDescription(), options);
}

RequireDebugAuthorization(webApp.MapGet("/debug/compare/{id}", async (string id, string baseUrl, string remoteTraceId,
RequireDebugAuthorization(webApp.MapGet($"{prefix}/compare/{{id}}", async (string id, string baseUrl, string remoteTraceId,
DebugEntryStore store,
DebugProbeOptions options) =>
{
Expand All @@ -191,9 +193,9 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac
return Results.BadRequest(validation.Error);
}

var remoteEnvironmentUrl = new Uri(validation.BaseUri!, "/debug/environment");
var remoteEnvironmentUrl = new Uri(validation.BaseUri!, $"{prefix}/environment");

var remoteEntryUrl = new Uri(validation.BaseUri!, $"/debug/json/{remoteTraceId}");
var remoteEntryUrl = new Uri(validation.BaseUri!, $"{prefix}/json/{remoteTraceId}");

DebugEntry? remoteEntry;
DebugEnvironment? remoteEnvironment;
Expand Down Expand Up @@ -246,13 +248,13 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.MapGet("/debug/environment", (DebugEntryStore store) =>
RequireDebugAuthorization(webApp.MapGet($"{prefix}/environment", (DebugEntryStore store) =>
{
return Results.Ok(store.Environment);

}).ExcludeFromDescription(), options);

RequireDebugAuthorization(webApp.MapGet("/debug/json/{id}", (string id, DebugEntryStore store) =>
RequireDebugAuthorization(webApp.MapGet($"{prefix}/json/{{id}}", (string id, DebugEntryStore store) =>
{
var item = store.Get(id);

Expand Down
2 changes: 1 addition & 1 deletion DebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class DebugProbeMiddleware

private static readonly string[] DefaultIgnorePaths =
[
"/debug",
"/compare",
"/swagger",
"/health",
Expand Down Expand Up @@ -161,6 +160,7 @@ private bool IsIgnoredPath(PathString requestPath)

return DefaultIgnorePaths
.Concat(_options.IgnorePaths)
.Append(_options.RoutePrefix)
.Distinct(StringComparer.OrdinalIgnoreCase)
.Any(ignorePath =>
path.Equals(ignorePath, StringComparison.OrdinalIgnoreCase) ||
Expand Down
13 changes: 13 additions & 0 deletions DebugProbe.AspNetCore/Options/DebugProbeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,17 @@ public int MaxBodyCaptureSizeKb
/// Value used when sensitive data is redacted.
/// </summary>
public string RedactionText { get; set; } = "[REDACTED]";

/// <summary>
/// The route prefix for the DebugProbe dashboard and API endpoints.
/// Defaults to <c>"/debug"</c>. A leading slash is added automatically if omitted.
/// </summary>
private string _routePrefix = "/debug";
public string RoutePrefix
{
get => _routePrefix;
set => _routePrefix = string.IsNullOrWhiteSpace(value)
? "/debug"
: "/" + value.TrimStart('/');
}
}
Loading