aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-05-07 13:55:22 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-05-07 14:11:08 -0500
commit2391114fbcadba7378451c8a066fb466269fdb13 (patch)
tree3638bc7683b68b0304c2a7ad32c3c9316b123acf
parent022905ad5d076bbf2969328a6cb5c2daee182763 (diff)
downloadslskd-2391114fbcadba7378451c8a066fb466269fdb13.tar.gz
docs
-rw-r--r--src/slskd/Program.cs14
-rw-r--r--src/web/package.json2
-rw-r--r--src/web/public/index.html2
3 files changed, 7 insertions, 11 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 91ce72f7..ecf028b4 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -612,7 +612,7 @@ namespace slskd
// inject urlBase into any html files we serve, and rewrite links to ./static or /static to
// prepend the url base.
app.UsePathBase(urlBase);
- app.UseHTMLRewrite("((\\.)?\\/static)", $"{urlBase}/static");
+ app.UseHTMLRewrite("((\\.)?\\/static)", $"{(urlBase == "/" ? string.Empty : urlBase)}/static");
app.UseHTMLInjection($"<script>window.urlBase=\"{urlBase}\"</script>");
Log.Information("Using base url {UrlBase}", urlBase);
@@ -683,14 +683,11 @@ namespace slskd
}
// if we made it this far, the caller is either looking for a route that was synthesized with a SPA router, or is genuinely confused.
- // optimistically search the dictionary of static files to see if we have a file that matches, and serve it if so.
+ // if the request is for a directory, modify the request to redirect it to the index, otherwise leave it alone and let it 404 in the next
+ // middleware
app.Use(async (context, next) =>
{
- var path = context.Request.Path.ToString();
-
- // if there is no extension, the caller is looking for a directory (an index file)
- // modify the request to get the canonical default index
- if (Path.GetExtension(path) == string.Empty)
+ if (Path.GetExtension(context.Request.Path.ToString()) == string.Empty)
{
context.Request.Path = "/";
}
@@ -698,8 +695,7 @@ namespace slskd
await next();
});
- // the request path may have been rewritten above, in which case we're likely to have better luck finding
- // a match with the file server middleware. let it try, and if it fails let it return a 404.
+ // either serve the index, or 404
app.UseFileServer(fileServerOptions);
return app;
diff --git a/src/web/package.json b/src/web/package.json
index 62b72a55..a8810d47 100644
--- a/src/web/package.json
+++ b/src/web/package.json
@@ -52,4 +52,4 @@
"not op_mini all"
]
}
-} \ No newline at end of file
+}
diff --git a/src/web/public/index.html b/src/web/public/index.html
index 5b30bc65..e452c8c8 100644
--- a/src/web/public/index.html
+++ b/src/web/public/index.html
@@ -9,4 +9,4 @@
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
-</html> \ No newline at end of file
+</html>