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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user