Skip to content

Commit f9747af

Browse files
committed
Add static frontend support.
1 parent 4e99f49 commit f9747af

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.FileProviders;
4+
5+
namespace Initium.Extensions;
6+
7+
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
8+
public static class StaticFrontendExtensions
9+
{
10+
public static IApplicationBuilder MapStaticFrontend(this IApplicationBuilder app, string clientPath)
11+
{
12+
app.UseDefaultFiles(new DefaultFilesOptions
13+
{
14+
FileProvider = new PhysicalFileProvider(clientPath),
15+
RequestPath = "",
16+
DefaultFileNames = new List<string> { "index.html" }
17+
});
18+
19+
app.UseStaticFiles(new StaticFileOptions
20+
{
21+
FileProvider = new PhysicalFileProvider(clientPath),
22+
RequestPath = ""
23+
});
24+
25+
// TODO: A quoi sert MapFallbackToFile?
26+
// app.MapFallbackToFile("index.html", Path.Combine(clientPath, "index.html"));
27+
28+
return app;
29+
}
30+
}

0 commit comments

Comments
 (0)