aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-09-13 19:34:57 -0500
committerJP Dillingham <jp@dillingham.me>2026-09-13 19:34:57 -0500
commitf857fa37a94bac0967f31d56b839e699b39db427 (patch)
treea5519ed4082fed48ee64300effbe1f5d51fd31d1 /src/slskd/Program.cs
parent5699bcf9fde961105b917350b720803c869566f2 (diff)
parent92167f6f1657703959d6ea94e4af82169c5c5fba (diff)
downloadslskd-f857fa37a94bac0967f31d56b839e699b39db427.tar.gz
Merge remote-tracking branch 'origin/master' into enumerate
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index c998d319..b1f57ce4 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -1067,12 +1067,17 @@ namespace slskd
var urlBase = OptionsAtStartup.Web.UrlBase;
urlBase = urlBase.StartsWith("/") ? urlBase : "/" + urlBase;
- // use urlBase. this effectively just removes urlBase from the path.
- // inject urlBase into any html files we serve, and rewrite links to ./static or /static to
- // prepend the url base.
+ // use urlBase. this effectively just removes urlBase from the path before sending it to the next middleware
app.UsePathBase(urlBase);
+
+ // rewrite relative html links to ./static or ./favicon.ico to absolute links that include urlBase
+ // this is necessary because SPA routers (like React Router) mess with the browser's current address
app.UseHTMLRewrite("((\\.)?\\/static)", $"{(urlBase == "/" ? string.Empty : urlBase)}/static");
+ app.UseHTMLRewrite("((\\.)?\\/favicon\\.ico)", $"{(urlBase == "/" ? string.Empty : urlBase)}/favicon.ico");
+
+ // inject urlBase and port into any html files we serve as a window-scoped javascript variable
app.UseHTMLInjection($"<script>window.urlBase=\"{urlBase}\";window.port={OptionsAtStartup.Web.Port}</script>", excludedRoutes: new[] { "/api", "/swagger" });
+
Log.Information("Using base url {UrlBase}", urlBase);
// serve static content from the configured path