aspnetcore
aspnetcore copied to clipboard
allow configure static files with `IOptions<T>` and `IConfiguration`
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
when I create a proxy service with YARP , I need to serve static files like nginx, but it need to be able to configure mime type mapping throw appsettings.json.
https://github.com/dotnet/aspnetcore/blob/369b2dedc04c58d20322a71d2d8eb255615d5757/src/Middleware/StaticFiles/src/StaticFileExtensions.cs#L25-L30
the "default" UseStaticFile indeed use IOptions<StaticFileOptions>, but it is a Singleton service injected to constructor
and it can not to configure it through appsettings.json
Describe the solution you'd like
- use a new base method
UseStaticFile(this IApplicationBuilder app,Func<IServiceProvider, IOptionsMonitor<StaticFileOptions>>) - middleware use
IOptionsMonitor<StaticFileOptions>> - add an easy configuration structure
{
"StaticFile": {
"AllowDefaultMappings": true, // default to true, false will clear all default mime mappings
"Mappings" : {
".apk":"application/vnd.android.package-archive",
".xxx":"yyyyyyyy"
},
"ServeUnknownFileTypes":false,
"RedirectToAppendTrailingSlash":fase,
"DefaultFileNames":[ // this is for configure UseDefaultFiles
"index.html",
"index.htm"
]
}
}
Additional context
No response