Skip to content

Commit 7adb64e

Browse files
committed
feat: add configurable RoutePrefix to DebugProbeOptions
1 parent 368b5f6 commit 7adb64e

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

DebugProbe.AspNetCore/Extensions/DebugProbeExtensions.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Net.Http.Json;
1+
using System.Net.Http.Json;
22
using DebugProbe.AspNetCore.Handlers;
33
using DebugProbe.AspNetCore.Internal.Compare;
44
using DebugProbe.AspNetCore.Internal.Rendering;
@@ -90,9 +90,11 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac
9090

9191
if (app is WebApplication webApp)
9292
{
93+
var prefix = options.RoutePrefix;
94+
9395
if (ShouldMapUiEndpoints(environment, options))
9496
{
95-
RequireDebugAuthorization(webApp.MapGet("/debug", async (HttpContext ctx, DebugEntryStore store) =>
97+
RequireDebugAuthorization(webApp.MapGet(prefix, async (HttpContext ctx, DebugEntryStore store) =>
9698
{
9799
var items = store.GetAll()
98100
.OrderByDescending(x => x.Timestamp)
@@ -105,7 +107,7 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac
105107

106108
}).ExcludeFromDescription(), options);
107109

108-
RequireDebugAuthorization(webApp.MapGet("/debug/{id}", async (HttpContext ctx, string id, DebugEntryStore store) =>
110+
RequireDebugAuthorization(webApp.MapGet($"{prefix}/{{id}}", async (HttpContext ctx, string id, DebugEntryStore store) =>
109111
{
110112
var item = store.Get(id);
111113

@@ -139,7 +141,7 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac
139141

140142
}).ExcludeFromDescription(), options);
141143

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

151153
}).ExcludeFromDescription(), options);
152154

153-
RequireDebugAuthorization(webApp.MapPost("/debug/clear", (DebugEntryStore store) =>
155+
RequireDebugAuthorization(webApp.MapPost($"{prefix}/clear", (DebugEntryStore store) =>
154156
{
155157
store.Clear();
156158

157159
return Results.Ok();
158160

159161
}).ExcludeFromDescription(), options);
160162

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

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

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

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

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

198200
DebugEntry? remoteEntry;
199201
DebugEnvironment? remoteEnvironment;
@@ -246,13 +248,13 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app, Ac
246248

247249
}).ExcludeFromDescription(), options);
248250

249-
RequireDebugAuthorization(webApp.MapGet("/debug/environment", (DebugEntryStore store) =>
251+
RequireDebugAuthorization(webApp.MapGet($"{prefix}/environment", (DebugEntryStore store) =>
250252
{
251253
return Results.Ok(store.Environment);
252254

253255
}).ExcludeFromDescription(), options);
254256

255-
RequireDebugAuthorization(webApp.MapGet("/debug/json/{id}", (string id, DebugEntryStore store) =>
257+
RequireDebugAuthorization(webApp.MapGet($"{prefix}/json/{{id}}", (string id, DebugEntryStore store) =>
256258
{
257259
var item = store.Get(id);
258260

DebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class DebugProbeMiddleware
2020

2121
private static readonly string[] DefaultIgnorePaths =
2222
[
23-
"/debug",
2423
"/compare",
2524
"/swagger",
2625
"/health",
@@ -161,6 +160,7 @@ private bool IsIgnoredPath(PathString requestPath)
161160

162161
return DefaultIgnorePaths
163162
.Concat(_options.IgnorePaths)
163+
.Append(_options.RoutePrefix)
164164
.Distinct(StringComparer.OrdinalIgnoreCase)
165165
.Any(ignorePath =>
166166
path.Equals(ignorePath, StringComparison.OrdinalIgnoreCase) ||

DebugProbe.AspNetCore/Options/DebugProbeOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,17 @@ public int MaxBodyCaptureSizeKb
8181
/// Value used when sensitive data is redacted.
8282
/// </summary>
8383
public string RedactionText { get; set; } = "[REDACTED]";
84+
85+
/// <summary>
86+
/// The route prefix for the DebugProbe dashboard and API endpoints.
87+
/// Defaults to <c>"/debug"</c>. A leading slash is added automatically if omitted.
88+
/// </summary>
89+
private string _routePrefix = "/debug";
90+
public string RoutePrefix
91+
{
92+
get => _routePrefix;
93+
set => _routePrefix = string.IsNullOrWhiteSpace(value)
94+
? "/debug"
95+
: "/" + value.TrimStart('/');
96+
}
8497
}

0 commit comments

Comments
 (0)