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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user