diff --git a/server/app/app.go b/server/app/app.go index cd09a7c2f..13f27c61e 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -53,7 +53,7 @@ func (app *Router) routes(path string) http.Handler { }) // Serve UI app assets - r.Handle("/", ServeIndex(app.ds)) + r.Handle("/", ServeIndex(app.ds, assets.AssetFile())) r.Handle("/*", http.StripPrefix(path, http.FileServer(assets.AssetFile()))) return r diff --git a/server/app/serve_index.go b/server/app/serve_index.go index 0752a78a9..f2b175cdc 100644 --- a/server/app/serve_index.go +++ b/server/app/serve_index.go @@ -7,7 +7,6 @@ import ( "net/http" "strings" - "github.com/deluan/navidrome/assets" "github.com/deluan/navidrome/conf" "github.com/deluan/navidrome/consts" "github.com/deluan/navidrome/log" @@ -15,13 +14,12 @@ import ( ) // Injects the `firstTime` config in the `index.html` template -func ServeIndex(ds model.DataStore) http.HandlerFunc { +func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { c, err := ds.User(r.Context()).CountAll() firstTime := c == 0 && err == nil t := template.New("initial state") - fs := assets.AssetFile() indexHtml, err := fs.Open("index.html") if err != nil { log.Error(r, "Could not find `index.html` template", err) diff --git a/server/app/serve_index_test.go b/server/app/serve_index_test.go index 9eaa58010..20f914ee8 100644 --- a/server/app/serve_index_test.go +++ b/server/app/serve_index_test.go @@ -3,6 +3,7 @@ package app import ( "encoding/json" "fmt" + "net/http" "net/http/httptest" "regexp" "strconv" @@ -17,6 +18,7 @@ import ( var _ = Describe("ServeIndex", func() { var ds model.DataStore mockUser := &mockedUserRepo{} + fs := http.Dir("tests/fixtures") BeforeEach(func() { ds = &persistence.MockDataStore{MockedUser: mockUser} @@ -26,7 +28,7 @@ var _ = Describe("ServeIndex", func() { r := httptest.NewRequest("GET", "/index.html", nil) w := httptest.NewRecorder() - ServeIndex(ds)(w, r) + ServeIndex(ds, fs)(w, r) Expect(w.Code).To(Equal(200)) config := extractAppConfig(w.Body.String()) @@ -38,7 +40,7 @@ var _ = Describe("ServeIndex", func() { r := httptest.NewRequest("GET", "/index.html", nil) w := httptest.NewRecorder() - ServeIndex(ds)(w, r) + ServeIndex(ds, fs)(w, r) config := extractAppConfig(w.Body.String()) Expect(config).To(HaveKeyWithValue("firstTime", true)) @@ -49,7 +51,7 @@ var _ = Describe("ServeIndex", func() { r := httptest.NewRequest("GET", "/index.html", nil) w := httptest.NewRecorder() - ServeIndex(ds)(w, r) + ServeIndex(ds, fs)(w, r) config := extractAppConfig(w.Body.String()) Expect(config).To(HaveKeyWithValue("firstTime", false)) @@ -60,7 +62,7 @@ var _ = Describe("ServeIndex", func() { r := httptest.NewRequest("GET", "/index.html", nil) w := httptest.NewRecorder() - ServeIndex(ds)(w, r) + ServeIndex(ds, fs)(w, r) config := extractAppConfig(w.Body.String()) Expect(config).To(HaveKeyWithValue("baseURL", "base_url_test")) diff --git a/tests/fixtures/index.html b/tests/fixtures/index.html new file mode 100644 index 000000000..f93ce189c --- /dev/null +++ b/tests/fixtures/index.html @@ -0,0 +1,16 @@ + + +
+ + +