From 27ed3689f23b379c68eb691631b7e4b3bd7b69b6 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 29 May 2026 18:44:10 +0200 Subject: [PATCH] Adjust YARP proxy to exclude specific API paths Updated the middleware pipeline in `Program.cs` to use `app.MapWhen()` for conditional routing. The reverse proxy now excludes requests to `/swagger`, `/scalar`, and `/openapi` paths, ensuring these endpoints are handled separately. This change replaces the direct `app.MapReverseProxy()` call with a more selective approach, improving request handling for specific API paths. --- EnvelopeGenerator.API/Program.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.API/Program.cs b/EnvelopeGenerator.API/Program.cs index f2478083..e7d29141 100644 --- a/EnvelopeGenerator.API/Program.cs +++ b/EnvelopeGenerator.API/Program.cs @@ -322,9 +322,19 @@ try app.UseAuthentication(); app.UseAuthorization(); - app.MapReverseProxy(); app.MapControllers(); + // Catch-all YARP proxy — only forward requests that are not swagger/scalar/openapi paths. + app.MapWhen( + ctx => + { + var path = ctx.Request.Path.Value ?? string.Empty; + return !path.StartsWith("/swagger", StringComparison.OrdinalIgnoreCase) && + !path.StartsWith("/scalar", StringComparison.OrdinalIgnoreCase) && + !path.StartsWith("/openapi", StringComparison.OrdinalIgnoreCase); + }, + branch => branch.UseRouting().UseEndpoints(e => e.MapReverseProxy())); + app.Run(); } catch (Exception ex)