Files
duplicati/Duplicati/WebserverCore/Middlewares/StaticFilesMiddleware.cs
T
Kenneth Skovhede 3f29642f6c Implemented JWT tokens.
Added auth requirement on all endpoints.
Added SignIn-, Access- and Refresh-Tokens based on JWT.
Upgraded stored password to be based on PBKDF2.
Added default password assignment.
Updated logic to support auth-header and re-sign-in for tray-icon and web-ui.
2024-06-19 13:54:10 +02:00

46 lines
1.5 KiB
C#

using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;
namespace Duplicati.WebserverCore.Middlewares;
public static class StaticFilesExtensions
{
public static IApplicationBuilder UseDefaultStaticFiles(this WebApplication app, string webroot)
{
var fileProvider = new PhysicalFileProvider(Path.GetFullPath(webroot));
var defaultFiles = GetDefaultFiles(fileProvider);
app.UseDefaultFiles(defaultFiles);
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = "",
ContentTypeProvider = new FileExtensionContentTypeProvider()
{
Mappings = {
["htc"] = "text/x-component",
["json"] = "application/json",
["map"] = "application/json",
["htm"] = "text/html; charset=utf-8",
["html"] = "text/html; charset=utf-8",
["hbs"] = "application/x-handlebars-template",
["woff"] = "application/font-woff",
["woff2"] = "application/font-woff",
}
}
});
return app;
}
private static DefaultFilesOptions GetDefaultFiles(PhysicalFileProvider fileProvider)
{
var defaultFiles = new DefaultFilesOptions
{
FileProvider = fileProvider
};
defaultFiles.DefaultFileNames.Clear();
defaultFiles.DefaultFileNames.Add("index.html");
return defaultFiles;
}
}