Skip to content

Commit

Permalink
fix 404 error in web UI (#665)
Browse files Browse the repository at this point in the history
Co-authored-by: crwxaj <crwxaj>
  • Loading branch information
crwxaj authored Jan 14, 2022
1 parent 17817d7 commit 61b7cf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 1 addition & 5 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ func StartServer(version, commit, branch, date string) {
restful.Add(restfulspec.NewOpenAPIService(restConfig))

// Static files
if !common.EnvConfig.Debug {
authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.StripPrefix("/dist/", http.FileServer(http.FS(ui.Assets))))
} else {
authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.FileServer(http.Dir("ui/dist")))
}
authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.FileServer(ui.GetFileSystem(common.EnvConfig.Debug)))

// Imageproxy
r := mux.NewRouter()
Expand Down
19 changes: 18 additions & 1 deletion ui/fs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package ui

import "embed"
import (
"embed"
"io/fs"
"log"
"net/http"
)

//go:embed dist
var Assets embed.FS

func GetFileSystem(useOS bool) http.FileSystem {
if useOS {
return http.Dir("ui/dist")
}

fs, err := fs.Sub(Assets, "dist")
if err != nil {
log.Panic(err)
}
return http.FS(fs)
}

0 comments on commit 61b7cf8

Please sign in to comment.