diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-09-09 18:44:51 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-09-09 18:44:51 -0500 |
| commit | bcbb9839144a64df12ecbff26e465129054a5354 (patch) | |
| tree | 921c15d4fb234e676a59a259249edd19920f0353 /src/slskd/Program.cs | |
| parent | d5c3922ad1b8093c208fdf6ab5239af0b036c65c (diff) | |
| download | slskd-bcbb9839144a64df12ecbff26e465129054a5354.tar.gz | |
rewrite ./favicon.ico so it's prefixed by urlBase
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 11 |
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 |
