Add YARP reverse proxy for auth request forwarding
Added the `Yarp.ReverseProxy` package and configured the app to use YARP for forwarding specific authentication-related API requests to an external service (`auth-hub`). Updated `Program.cs` to load YARP configuration from a new `yarp.json` file and added middleware to map unmatched requests to the reverse proxy. Replaced old routes and clusters with new routes (`auth-login`, `auth-envelope-receiver-login`) and a new cluster (`auth-hub`) pointing to `https://localhost:9090`. Configured route transformations for path and query parameter adjustments. These changes improve modularity and scalability by enabling dynamic reverse proxy configuration and external service integration.
This commit is contained in:
@@ -32,6 +32,9 @@ try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Load YARP configuration from yarp.json
|
||||
builder.Configuration.AddJsonFile("yarp.json", optional: true, reloadOnChange: true);
|
||||
|
||||
builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
|
||||
if (!builder.Environment.IsDevelopment())
|
||||
@@ -53,6 +56,10 @@ try
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
// YARP Reverse Proxy (for forwarding auth requests to AuthHub)
|
||||
builder.Services.AddReverseProxy()
|
||||
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
|
||||
|
||||
// HttpContextAccessor needed for SSR HttpClient configuration
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
@@ -370,6 +377,9 @@ try
|
||||
// API Controllers (map before Blazor routing)
|
||||
app.MapControllers();
|
||||
|
||||
// YARP Reverse Proxy - forwards unmatched requests to configured backends
|
||||
app.MapReverseProxy();
|
||||
|
||||
// Blazor routing
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode()
|
||||
|
||||
Reference in New Issue
Block a user