I'm implementing YARP (Yet Another Reverse Proxy) in my Blazor Server application to proxy multiple projects, but I'm facing some issues.
Issues Observed:
- Static Files (CSS/JS) Not Loading - 404 Errors
The browser console shows multiple Failed to load resource: the server responded with a status of 404.
Example missing files
error message
Blazor Circuit Initialization Failure
- After the WebSocket connection is established, I get the following error:
[Error] The circuit failed to initialize. Connection disconnected.
Project Setup & Code Snippets
Program.cs Configuration
builder.Services.AddReverseProxy();
builder.Services.AddSingleton<IProxyConfigProvider, DynamicProxyConfigProvider>();
app.UseStaticFiles();
app.MapReverseProxy();
app.MapRazorComponents().AddInteractiveServerRenderMode();
DynamicProxyConfigProvider.cs (Route & Cluster Configuration)
routes.Add(new RouteConfig
{
RouteId = routeId,
ClusterId = clusterId,
Match = new RouteMatch { Path = $"{proxiedUrl}/{{**catch-all}}" },
Transforms = new List<Dictionary<string, string>>
{
new Dictionary<string, string> { { "PathRemovePrefix", proxiedUrl } }
}
});
clusters.Add(new ClusterConfig
{
ClusterId = clusterId,
Destinations = new Dictionary<string, DestinationConfig>
{
{ "destination", new DestinationConfig { Address = item.Url } }
}
});
Index Page (Navigation to Proxy URL)
string sanitizedTitle = Uri.EscapeDataString(item.Title.Trim().Replace(" ", "-").ToLower());
string proxiedUrl = $"/system/{sanitizedTitle}-{item.Id}";
Navigation.NavigateTo(proxiedUrl, true);
Steps to Reproduce:
Set up a Blazor Server app with YARP to proxy an external Blazor app. Open the browser console (F12) to see 404 errors for static files and note a circuit failure when initializing a Blazor session.
What I Have Tried: Ensured Static Files Exist in wwwroot. Added UseStaticFiles() before UseRouting(). Checked _content/ Paths for Blazor resources. Enabled WebSockets in YARP. Modified appsettings.json to match YARP paths.
Expected Behavior: Static files should load correctly.
Environment:
.NET Version: net9.0 YARP Version: 2.3.0 Blazor Server Framework Version: net9.0 Hosting Environment: Localhost (https://localhost:7287) Browser: Edge
Questions:
How do I ensure YARP properly serves static files?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745101291a4611288.html
评论列表(0条)