Add profiling endpoints

This commit is contained in:
Melody Becker 2024-10-15 21:26:48 +02:00
parent 391d8b1b48
commit 124fc0ecac
4 changed files with 88 additions and 2 deletions

View file

@ -1,13 +1,13 @@
package server
import (
"fmt"
"io/fs"
"net/http"
"github.com/mstarongithub/passkey"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/goutils/other"
"gitlab.com/mstarongitlab/linstrom/config"
"gitlab.com/mstarongitlab/linstrom/storage"
)
@ -32,7 +32,18 @@ func buildRootHandler(pkey *passkey.Passkey, reactiveFS, staticFS fs.FS) http.Ha
pkey.MountRoutes(mux, "/webauthn/")
mux.Handle("/", setupFrontendRouter(reactiveFS, staticFS))
mux.Handle("/pk/", http.StripPrefix("/pk", http.FileServer(http.Dir("pk-auth"))))
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, true) })
mux.HandleFunc("/alive", isAliveHandler)
profilingHandler := setupProfilingHandler()
mux.Handle("/profiling/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Only allow access to profiling if a password is provided and it matches the one in the config
if r.FormValue("password") != config.GlobalConfig.Admin.ProfilingPassword {
// Specifically reply with a plain 404
http.Error(w, "", 404)
return
}
profilingHandler.ServeHTTP(w, r)
}))
mux.Handle(
"/authonly/",
pkey.Auth(