Skip to content
Permalink
Browse files

Make webui serve index.html on unknown urls.

  • Loading branch information...
Cazzar committed May 15, 2019
1 parent 5c1f94f commit ffab94546f10f77fe2afb8dcb25de4e93a9889c1
Showing with 25 additions and 2 deletions.
  1. +25 −2 Shoko.Server/API/Startup.cs
@@ -18,8 +18,10 @@
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.FileProviders.Physical;
using Newtonsoft.Json;
using NLog;
using Microsoft.Extensions.Primitives;

namespace Shoko.Server.API
{
@@ -152,10 +154,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(dir.FullName),
RequestPath = "/webui"
FileProvider = new WebUiFileProvider(dir.FullName),
RequestPath = "/webui",
ServeUnknownFileTypes = true
});


app.UseSwagger();
app.UseSwaggerUI(
options =>
@@ -275,6 +279,25 @@ public string Read(HttpRequest request)
}
}

internal class WebUiFileProvider : PhysicalFileProvider, IFileProvider
{
public WebUiFileProvider(string root) : base(root)
{
}

public new IDirectoryContents GetDirectoryContents(string subpath)
{
return base.GetDirectoryContents(subpath);
}

public new IFileInfo GetFileInfo(string subpath)
{
var fileInfo = base.GetFileInfo(subpath);
if (fileInfo is NotFoundFileInfo || !fileInfo.Exists) return base.GetFileInfo("index.html");
return fileInfo;
}
}

public class SwaggerDefaultValues : IOperationFilter
{
/// <summary>

0 comments on commit ffab945

Please sign in to comment.
You can’t perform that action at this time.