chore: enable all pprof handle on debug

pull/5205/head
Andy Hsu 2023-09-07 14:56:50 +08:00
parent d5b68a91d2
commit cd2f8077fa
3 changed files with 16 additions and 7 deletions

View File

@ -1,12 +1,20 @@
package server package server
import ( import (
"net/http"
_ "net/http/pprof"
"runtime"
"github.com/alist-org/alist/v3/server/common" "github.com/alist-org/alist/v3/server/common"
"github.com/alist-org/alist/v3/server/middlewares" "github.com/alist-org/alist/v3/server/middlewares"
"github.com/gin-gonic/gin" "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) { g.GET("/path/*path", middlewares.Down, func(ctx *gin.Context) {
rawPath := ctx.MustGet("path").(string) rawPath := ctx.MustGet("path").(string)
ctx.JSON(200, gin.H{ ctx.JSON(200, gin.H{
@ -16,4 +24,9 @@ func dev(g *gin.RouterGroup) {
g.GET("/hide_privacy", func(ctx *gin.Context) { g.GET("/hide_privacy", func(ctx *gin.Context) {
common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400) 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"))
} }

View File

@ -71,8 +71,8 @@ func Init(e *gin.Engine) {
_fs(auth.Group("/fs")) _fs(auth.Group("/fs"))
admin(auth.Group("/admin", middlewares.AuthAdmin)) admin(auth.Group("/admin", middlewares.AuthAdmin))
if flags.Dev { if flags.Debug || flags.Dev {
dev(g.Group("/dev")) debug(g.Group("/debug"))
} }
static.Static(g, func(handlers ...gin.HandlerFunc) { static.Static(g, func(handlers ...gin.HandlerFunc) {
e.NoRoute(handlers...) e.NoRoute(handlers...)

View File

@ -5,10 +5,8 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"net/http" "net/http"
"net/http/pprof"
"strings" "strings"
"github.com/alist-org/alist/v3/cmd/flags"
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/utils" "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) c.Status(200)
if strings.HasPrefix(c.Request.URL.Path, "/@manage") { if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
_, _ = c.Writer.WriteString(conf.ManageHtml) _, _ = c.Writer.WriteString(conf.ManageHtml)
} else if strings.HasPrefix(c.Request.URL.Path, "/debug/pprof") && flags.Debug {
pprof.Index(c.Writer, c.Request)
} else { } else {
_, _ = c.Writer.WriteString(conf.IndexHtml) _, _ = c.Writer.WriteString(conf.IndexHtml)
} }