Fix SPA Server and 404 on IVirtualFileSystem

RouteServer now returns NotFoundServer or another server
MountableServer now can implicitly support NotFoundServer
This commit is contained in:
Mike Nolan
2023-06-08 14:04:59 -05:00
parent e75b2048c9
commit 5e557faaaf
7 changed files with 54 additions and 12 deletions
+8 -3
View File
@@ -604,7 +604,7 @@ namespace Tesses.WebServer
{
foreach(var def in _defaultFileNames)
{
var _name = Special.Root / path;
var _name = Special.Root / path / def; //woops we need the def here
name=_name.Path;
if(_fs.FileExists(_name))
{
@@ -1072,12 +1072,13 @@ namespace Tesses.WebServer
case WebServerPathType.NotFound:
if(RedirectToRootInsteadOfNotFound)
{
var fileEntry2 = fileHandler.GetPath("/");
switch(fileEntry.Type)
switch(fileEntry2.Type)
{
case WebServerPathType.File:
using(var strm = fileHandler.Open(fileEntry2))
await ctx.SendStreamAsync(strm,HeyRed.Mime.MimeTypesMap.GetMimeType(fileEntry.FileName));
await ctx.SendStreamAsync(strm,HeyRed.Mime.MimeTypesMap.GetMimeType(fileEntry2.FileName));
break;
case WebServerPathType.Directory:
if(AllowListingDirectories)
@@ -1336,6 +1337,10 @@ namespace Tesses.WebServer
public MountableServer(IServer root)
{
_root = root;
}
public MountableServer() : this(new NotFoundServer())
{
}
IServer _root;
private (string Key,IServer Value) GetFromPath(ServerContext ctx)