From 2391114fbcadba7378451c8a066fb466269fdb13 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 7 May 2022 13:55:22 -0500 Subject: docs --- src/slskd/Program.cs | 14 +++++--------- src/web/package.json | 2 +- src/web/public/index.html | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src') 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($""); 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 @@
- \ No newline at end of file + -- cgit v1.2.3