aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-06 09:13:03 -0500
committerJP Dillingham <jp@dillingham.me>2022-05-06 09:13:03 -0500
commit399ca91729cdcd564eb367449c64c05c54258b52 (patch)
tree9470fb9e4bbc335ac37fda6b7d5feb42533f83ce /src/slskd/Program.cs
parent15b611ccd5cc3350743e1bae23def84938abe451 (diff)
downloadslskd-399ca91729cdcd564eb367449c64c05c54258b52.tar.gz
add middleware to rewrite HTML
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs30
1 files changed, 1 insertions, 29 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 0103688b..5a0749a1 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -614,6 +614,7 @@ namespace slskd
// why the enforcement behavior exists above (the actually requested path becomes ambiguous)
// inject urlBase into any html files we serve
app.UsePathBase(urlBase);
+ app.UseHTMLRewrite("((\\.)?\\/static)", $"{urlBase}/static");
app.UseHTMLInjection($"<script>window.urlBase=\"{urlBase}\"</script>");
Log.Information("Using base url {UrlBase}", urlBase);
@@ -695,35 +696,6 @@ namespace slskd
{
context.Request.Path = "/";
}
- else
- {
- HashSet<string> staticFiles;
-
- if (!Cache.TryGetValue(CacheKey.StaticFiles, out staticFiles))
- {
- staticFiles = System.IO.Directory.GetFiles(contentPath, "*", SearchOption.AllDirectories)
- .Select(file => file.Replace(contentPath, string.Empty).TrimStart('/', '\\').Replace('\\', '/'))
- .ToHashSet();
-
- Cache.Set(CacheKey.StaticFiles, staticFiles);
- }
-
- var pathParts = path.Split('/');
-
- for (int i = 1; i <= pathParts.Length; i++)
- {
- path = string.Join('/', pathParts.Skip(i));
-
- if (staticFiles.Contains(path, StringComparer.InvariantCultureIgnoreCase))
- {
- // the request is for a static file we have, but the route contains extra segments
- // correct the route and continue to the next middleware, which should serve the file from
- // disk.
- context.Request.Path = '/' + path;
- break;
- }
- }
- }
await next();
});