0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00
zot/pkg/extensions/extension-ui.go
Ramkumar Chinchani 97f1fc0f98 ui: initial commit
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
(cherry picked from commit d557da0baba819b7cd7e6b5941528776e125ac6d)
2022-09-14 16:32:15 +00:00

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")
}
}