-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use of new StaticFileOptions for Modules #10118
Conversation
lol, wow, I just started investigating the possibilities, ran into the issue, saw the workaround, and found it was being fixed soon. Gotta love open-source. :-D |
options.FileProvider = _fileProvider; | ||
} | ||
|
||
var cacheControl = _shellConfiguration.GetValue("StaticFileOptions:CacheControl", $"public, max-age={TimeSpan.FromDays(30).TotalSeconds}, s-max-age={TimeSpan.FromDays(365.25).TotalSeconds}"); |
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.
s-maxage
typo ?
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.
Since there are settings, maybe put these values in there too.
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.
looks like typo, will fix it. It's reading from settings if available- the second param is default fallback
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.
Updated code and docs to s-maxage
@@ -60,9 +60,12 @@ You can find a sample application here: [`OrchardCore.Mvc.Web`](../../../../Orch | |||
|
|||
The following configuration values are used by default and can be customized: | |||
|
|||
By default each tenant doesn't serve static files from Host `wwwroot`. To serve Host `wwwroot` for each tenant, set `ServeHostWebRoot` to `true` in tenant config. |
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.
Has it always been the case?
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.
Currently static files from Host wwwroot
is only served to Default
tenant (and not to other tenants) by configuring app.UseStaticFiles()
in Host startup before app.UseOrchardCore()
Keeping the same behavior by setting default value to false
_shellConfiguration = shellConfiguration; | ||
_environment = environment; | ||
} | ||
public void PostConfigure(string name, StaticFileOptions options) |
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.
Add new line before
name = name ?? throw new ArgumentNullException(nameof(name)); | ||
options = options ?? throw new ArgumentNullException(nameof(options)); | ||
|
||
if (name != Microsoft.Extensions.Options.Options.DefaultName) |
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.
Maybe add an using above so that here we could just use Options.DefaultName
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.
using Microsoft.Extensions.Options;
is already included at line 7, but compiler complains when use Options.DefaultName
{ | ||
// Serve Tenant Static files only from module | ||
options.FileProvider = _fileProvider; | ||
} |
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.
Maybe we still need to set options.RequestPath = ""
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.
As this could be vary based on source of static file and developer's configuration, may be we don't use PostConfigure and we just use new StaticFileOptions()
for module files?
} | ||
|
||
// Cache static files for a year as they are coming from embedded resources and should not vary | ||
ctx.Context.Response.Headers[HeaderNames.CacheControl] = cacheControl; |
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.
Hmm, but not fully true if we compose with the WebRootFileProvider
that may be related to not embedded files.
Maybe we need 2 UseStaticFiles()
, then maybe the same options but at least with 2 separate default values.
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.
As this could be vary based on source of static file, may be we don't use PostConfigure and we just use new StaticFileOptions()
for module files?
@ns8482e @sebastienros Just did a little review Hmm, for content root files each tenant already compose with OrchardCore/src/OrchardCore/OrchardCore/Modules/Extensions/ApplicationBuilderExtensions.cs Lines 20 to 22 in ac7598c
Maybe at the tenant level we could also compose with the Now not sure we need a post configuration, maybe jut a regular one, then as said in the review maybe a separate static file options as the Need a little more time to focus on it again ;) I will complete my review asap. |
The real issue is due to following lines, OrchardCore/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs Lines 210 to 213 in ac7598c
Line 210 evaluates So even if a developer uses IMHO that value of May be better option is not to use or configure var options = new StaticFileOptions();
options.RequestPath = "";
options.FileProvider = fileProvider; And Let developer control whether to serve files from |
@sebastienros @jtkech removed, IPostConfigureOptions |
@ns8482e Yes, I prefer this ;) And let people do what they want from the app with our helpers, e.g.
Maybe add it to the doc, and maybe saying that for mutating / collaborate to the related host options better to still do it at the host level. Note: As I remember, not so good at the tenant level to mutate host level options because we may build tenants concurrently, we had this kind of problem with routing services / options where we needed at the tenant level to remove from the DI some host level singleton services / configuration options before re-registering them. So okay for now that at the tenant level we always use a OrchardCore/src/OrchardCore.Modules/OrchardCore.Tenants/Startup.cs Lines 106 to 117 in c1f261f
Notice that here the For module embedded static files maybe we could use the same code pattern as above, then not sure about setting other properties e.g. Hmm, so one idea would be to still resolve the host level |
@jtkech @agriffard what would be accurate path to document this? IMHO This is related to framework and and not related to Tenant module. |
Or maybe in a section dedicated to static files but didn't find it, anyway should not block this PR. Last thing, what you think about still resolving the host level The idea is to work as before for modules static files but just without mutating the host So as you want ;) let me know before approving. |
@ns8482e IMHO, |
First for info I did some tests, when we resolve the options while building a tenant pipeline, we get a different instance per tenant, so no problem when building multiple tenants concurrently as I was talking about.
Okay but I was talking about still resolving it in our Anyway, I'm fine with just creating a new |
Suggested change: Still resolve options but without mutating it
Fix CI build
@jtkech verified the changes - it works! |
src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs
Show resolved
Hide resolved
Thanks for having tested it! |
Use of
new StaticFileOptions()
for module files, instead resolving from DI.Replaceapp.UseStaticFiles(options);
to useapp.UseStaticFiles();
and configuring Module's FileProviders inPostConfigure
.This allows external module ( e.g. Blazor Server) to inject any additional FileProviders in tenant's pipeline - that ultimately used by StaticFileMiddleware.Static Files from HostWebRoot can be served using
app.UseStaticFiles()
in tenant pipeline.Fixes #6505
Fixes #2966
Fixes #6474