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
+29 -6
View File
@@ -485,25 +485,47 @@ namespace Tesses.WebServer
public delegate void HttpAction(ServerContext ctx);
public class RouteServer : Server
{
public RouteServer() : this(new NotFoundServer())
{
}
public RouteServer(IServer otherServer)
{
this.otherServer=otherServer;
}
public List<(ShouldProcessFunc ShouldProcessFunc, HttpActionAsync Action)> Methods = new List<(ShouldProcessFunc ShouldProcessFunc, HttpActionAsync Action)>();
private IServer otherServer;
public override async Task GetAsync(ServerContext ctx)
{
await Process(ctx);
if(!await Process(ctx))
{
await Guaranteed(otherServer).GetAsync(ctx);
}
}
public override async Task PostAsync(ServerContext ctx)
{
await Process(ctx);
if(!await Process(ctx))
{
await Guaranteed(otherServer).PostAsync(ctx);
}
}
public override async Task OtherAsync(ServerContext ctx)
{
await Process(ctx);
if(!await Process(ctx))
{
await Guaranteed(otherServer).OtherAsync(ctx);
}
}
public override async Task OptionsAsync(ServerContext ctx)
{
await Process(ctx);
if(!await Process(ctx))
{
await Guaranteed(otherServer).OptionsAsync(ctx);
}
}
private async Task Process(ServerContext ctx)
private async Task<bool> Process(ServerContext ctx)
{
foreach(var (shouldProcessFunc,action) in Methods)
{
@@ -514,8 +536,9 @@ namespace Tesses.WebServer
}
await action(ctx);
return;
return true;
}
return false;
}
/// <summary>
/// Adds the specified action to the route collection.