mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
97f1fc0f98
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> (cherry picked from commit d557da0baba819b7cd7e6b5941528776e125ac6d)
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
//go:build search || ui_base
|
|
// +build search ui_base
|
|
|
|
package extensions
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"zotregistry.io/zot/pkg/log"
|
|
"zotregistry.io/zot/pkg/storage"
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
)
|
|
|
|
// content is our static web server content.
|
|
//go:embed build/*
|
|
var content embed.FS
|
|
|
|
func SetupUIRoutes(config *config.Config, router *mux.Router, storeController storage.StoreController,
|
|
l log.Logger,
|
|
) {
|
|
// fork a new zerolog child to avoid data race
|
|
log := log.Logger{Logger: l.With().Caller().Timestamp().Logger()}
|
|
|
|
if config.Extensions.UI != nil {
|
|
fsub, _ := fs.Sub(content, "build")
|
|
|
|
router.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
|
|
buf, _ := content.ReadFile("build/index.html")
|
|
|
|
_, err := w.Write(buf)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("unable to serve index.html")
|
|
}
|
|
})
|
|
|
|
router.HandleFunc("/home", func(w http.ResponseWriter, r *http.Request) {
|
|
buf, _ := content.ReadFile("build/index.html")
|
|
|
|
_, err := w.Write(buf)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("unable to serve index.html")
|
|
}
|
|
})
|
|
|
|
router.PathPrefix("/").Handler(http.FileServer(http.FS(fsub)))
|
|
log.Info().Msg("setting up ui routes")
|
|
}
|
|
}
|