28 lines
629 B
Go

package admin
import (
"embed"
"encoding/json"
"io/fs"
"net/http"
)
//go:embed static
var staticFS embed.FS
// NewHandler returns the admin dashboard HTTP handler.
func NewHandler(apiBaseURL string) http.Handler {
sub, err := fs.Sub(staticFS, "static")
if err != nil {
panic("admin static fs: " + err.Error())
}
mux := http.NewServeMux()
mux.HandleFunc("GET /config.json", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{"api_base": apiBaseURL})
})
mux.Handle("/", http.FileServer(http.FS(sub)))
return mux
}