arl / statsviz

🚀 Visualise your Go program runtime metrics in real time in the browser
MIT License
3.19k stars 121 forks source link

[bug] beego run statsviz has a javascript error #94

Open zsy619 opened 1 year ago

zsy619 commented 1 year ago

代码如下:

package handler

import (
    "net/http/pprof"

    "github.com/arl/statsviz"
    "github.com/beego/beego/v2/server/web"
    "github.com/beego/beego/v2/server/web/context"
)

func init() {
    // web.Router(defaultPprofPrefix, &PprofController{}, "*:Index")
    web.AutoPrefix(defaultPprofPrefix, &PprofController{})
    // web.Router(defaultStatsvizPrefix, &PprofController{}, "*:StatIndex")
    // web.Router(defaultStatsvizPrefix+":path([\\w]+)", &PprofController{}, "*:StatPath")
    // web.Router(defaultStatsvizPrefix+"ws", &PprofController{}, "*:StatWs")

    web.Any("/debug/pprof/", func(ctx *context.Context) {
        pprof.Index(ctx.ResponseWriter, ctx.Request)
    })

    web.Any(defaultStatsvizPrefix, func(ctx *context.Context) {
        statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    })

    web.Any(defaultStatsvizPrefix+":path([\\w]+)", func(ctx *context.Context) {
        statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    })

    web.Any(defaultStatsvizPrefix+"ws", func(ctx *context.Context) {
        statsviz.Ws.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    })
}

错误提示: image

arl commented 11 months ago

@zsy619 Did you find the problem?

I'm sorry I don't know the beego library. However the examples directory shows how to configure statsviz with many other libraries/frameworks.

Maybe there's one that is similar to beego?

mzzsfy commented 8 months ago
web.Any(defaultStatsvizPrefix+":path([\\w]+)", func(ctx *context.Context) {
      statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
  })

defaultStatsvizPrefix+":path([\\w]+)" It looks like it doesn't match the multi-level path, maybe it can be changed to defaultStatsvizPrefix+"*"

arl commented 8 months ago

I don't know beego myself, some examples have been added by the community. If you know how to fix that please don't hesitate to open a PR

mzzsfy commented 8 months ago

I don't know beego myself, some examples have been added by the community. If you know how to fix that please don't hesitate to open a PR

It seems to be a problem with his usage

arl commented 8 months ago
web.Any(defaultStatsvizPrefix+":path([\\w]+)", func(ctx *context.Context) {
        statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    })

defaultStatsvizPrefix+":path([\\w]+)" It looks like it doesn't match the multi-level path, maybe it can be changed to defaultStatsvizPrefix+"*"

@zsy619 did that solve the issue? It's more than one year old so I'll soon close it