-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fixed bug - Passing options to UseStaticFiles breaks Blazor Server #45897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
app.UseStaticFiles(options); | ||
|
||
var blazorEndpoint = endpoints.Map("/_framework/blazor.server.js", app.Build()) | ||
.WithDisplayName("Blazor static files"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach looks fairly plausible but would love to get @javiercn's take since he has focused a lot on how the server-side endpoints are set up and how static files are served.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work, the only "slight" concern that I have is that we loose the ability to server blazor.server.js independently of where we are serving the other endpoints, but I do not see a big drawback to it.
Essentially if you want to map blazor to a subdir, you need to call app.MapPath("subdir", sub => { sub.UseRouting(); sub.UseStaticFiles(); sub.UseEndpoints(e => e.MapComponentHub()); }
, set the base path on the document accordingly.
There might have been other ways to make it work that might not work now, but I do not think they are critical.
var blazorEndpoint = endpoints.Map("/_framework/blazor.server.js", app.Build()) | ||
.WithDisplayName("Blazor static files"); | ||
|
||
blazorEndpoint.Add((builder) => ((RouteEndpointBuilder)builder).Order = -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -1
here makes it so that this endpoint has priority over other endpoints independent of their specificity, so this means that a controller or a file are not going to match over this endpoint.
With that said, I think we should be a bit more conservative here as people might also register their own routes with a custom order, which might cause those routes to match over this one. For that reason, we should do something similar but opposite to what we do in MapFallbackToPage
and give it the lowest order possible (int.MinValue)
so that we can guarantee under most circumstances, no other route will match over this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only time this might cause issues is if someone customizes routing extensively, which I am not too worried about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change looks great.
We have plenty of time to get feedback on this if we missed anything.
{ | ||
var options = new StaticFileOptions | ||
{ | ||
FileProvider = new ManifestEmbeddedFileProvider(typeof(ComponentEndpointRouteBuilderExtensions).Assembly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the removal of OnPrepareResponse = CacheHeaderSettings.SetCacheHeaders
intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@campersau, thanks for noticing.
Fixed bug - Passing options to UseStaticFiles breaks Blazor Server
Tested manually by running sample BlazorServerApp.
Fixes #19578