🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Fix UI loading redirections. Should fix #906
Deluan3b0defefec95
diff --git a/server/app/serve_index.go b/server/app/serve_index.goindex 56bdebc7a..4c1c54610 100644--- a/server/app/serve_index.go+++ b/server/app/serve_index.go@@ -6,6 +6,7 @@ import ("io/fs""io/ioutil""net/http"+ "path""strings""github.com/microcosm-cc/bluemonday"@@ -19,6 +20,11 @@ import (func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {policy := bluemonday.UGCPolicy()return func(w http.ResponseWriter, r *http.Request) {+ base := path.Join(conf.Server.BaseURL, consts.URLPathUI)+ if r.URL.Path == base {+ http.Redirect(w, r, base+"/", 302)+ }+c, err := ds.User(r.Context()).CountAll()firstTime := c == 0 && err == nildiff --git a/server/app/serve_index_test.go b/server/app/serve_index_test.goindex a8e48f26f..a903b716d 100644--- a/server/app/serve_index_test.go+++ b/server/app/serve_index_test.go@@ -26,6 +26,16 @@ var _ = Describe("serveIndex", func() {conf.Server.UILoginBackgroundURL = ""})+ It("redirects bare /app path to /app/", func() {+ r := httptest.NewRequest("GET", "/app", nil)+ w := httptest.NewRecorder()++ serveIndex(ds, fs)(w, r)++ Expect(w.Code).To(Equal(302))+ Expect(w.Header().Get("Location")).To(Equal("/app/"))+ })+It("adds app_config to index.html", func() {r := httptest.NewRequest("GET", "/index.html", nil)w := httptest.NewRecorder()diff --git a/server/server.go b/server/server.goindex 5a03086b9..19c7c2d83 100644--- a/server/server.go+++ b/server/server.go@@ -61,7 +61,7 @@ func (a *Server) initRoutes() {r.Use(requestLogger)r.Use(robotsTXT(ui.Assets()))- indexHtml := path.Join(conf.Server.BaseURL, consts.URLPathUI, "index.html")+ indexHtml := path.Join(conf.Server.BaseURL, consts.URLPathUI)r.Get("/*", func(w http.ResponseWriter, r *http.Request) {http.Redirect(w, r, indexHtml, 302)})