diff --git a/server/dev.go b/server/debug.go similarity index 60% rename from server/dev.go rename to server/debug.go index d39ef7a0..081ef8c3 100644 --- a/server/dev.go +++ b/server/debug.go @@ -1,12 +1,20 @@ package server import ( + "net/http" + _ "net/http/pprof" + "runtime" + "github.com/alist-org/alist/v3/server/common" "github.com/alist-org/alist/v3/server/middlewares" "github.com/gin-gonic/gin" ) -func dev(g *gin.RouterGroup) { +func _pprof(g *gin.RouterGroup) { + g.Any("/*name", gin.WrapH(http.DefaultServeMux)) +} + +func debug(g *gin.RouterGroup) { g.GET("/path/*path", middlewares.Down, func(ctx *gin.Context) { rawPath := ctx.MustGet("path").(string) ctx.JSON(200, gin.H{ @@ -16,4 +24,9 @@ func dev(g *gin.RouterGroup) { g.GET("/hide_privacy", func(ctx *gin.Context) { common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400) }) + g.GET("/gc", func(c *gin.Context) { + runtime.GC() + c.String(http.StatusOK, "ok") + }) + _pprof(g.Group("/pprof")) } diff --git a/server/router.go b/server/router.go index 2e4b88e6..26e8e147 100644 --- a/server/router.go +++ b/server/router.go @@ -71,8 +71,8 @@ func Init(e *gin.Engine) { _fs(auth.Group("/fs")) admin(auth.Group("/admin", middlewares.AuthAdmin)) - if flags.Dev { - dev(g.Group("/dev")) + if flags.Debug || flags.Dev { + debug(g.Group("/debug")) } static.Static(g, func(handlers ...gin.HandlerFunc) { e.NoRoute(handlers...) diff --git a/server/static/static.go b/server/static/static.go index be1db2c6..62463793 100644 --- a/server/static/static.go +++ b/server/static/static.go @@ -5,10 +5,8 @@ import ( "fmt" "io/fs" "net/http" - "net/http/pprof" "strings" - "github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/pkg/utils" @@ -85,8 +83,6 @@ func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) { c.Status(200) if strings.HasPrefix(c.Request.URL.Path, "/@manage") { _, _ = c.Writer.WriteString(conf.ManageHtml) - } else if strings.HasPrefix(c.Request.URL.Path, "/debug/pprof") && flags.Debug { - pprof.Index(c.Writer, c.Request) } else { _, _ = c.Writer.WriteString(conf.IndexHtml) }