server: add config option to enable pprof endpoints

This commit is contained in:
Tulir Asokan 2024-10-15 02:19:21 +03:00
parent 08bea53cf1
commit 038e62120b
2 changed files with 9 additions and 4 deletions

View file

@ -36,10 +36,11 @@ type Config struct {
} }
type WebConfig struct { type WebConfig struct {
ListenAddress string `yaml:"listen_address"` ListenAddress string `yaml:"listen_address"`
Username string `yaml:"username"` Username string `yaml:"username"`
PasswordHash string `yaml:"password_hash"` PasswordHash string `yaml:"password_hash"`
TokenKey string `yaml:"token_key"` TokenKey string `yaml:"token_key"`
DebugEndpoints bool `yaml:"debug_endpoints"`
} }
var defaultConfig = Config{ var defaultConfig = Config{

View file

@ -24,6 +24,7 @@ import (
"errors" "errors"
"io/fs" "io/fs"
"net/http" "net/http"
_ "net/http/pprof"
"strings" "strings"
"time" "time"
@ -52,6 +53,9 @@ func (gmx *Gomuks) StartServer() {
gmx.AuthMiddleware, gmx.AuthMiddleware,
) )
router := http.NewServeMux() router := http.NewServeMux()
if gmx.Config.Web.DebugEndpoints {
router.Handle("/debug/", http.DefaultServeMux)
}
router.Handle("/_gomuks/", apiHandler) router.Handle("/_gomuks/", apiHandler)
if frontend, err := fs.Sub(web.Frontend, "dist"); err != nil { if frontend, err := fs.Sub(web.Frontend, "dist"); err != nil {
gmx.Log.Warn().Msg("Frontend not found") gmx.Log.Warn().Msg("Frontend not found")