diff --git a/pkg/server/web/admin.go b/pkg/server/web/admin.go index 148ab806..46c0f738 100644 --- a/pkg/server/web/admin.go +++ b/pkg/server/web/admin.go @@ -46,23 +46,9 @@ var beeAdminApp *adminApp var FilterMonitorFunc func(string, string, time.Duration, string, int) bool func init() { - c := &adminController{ - servers: make([]*HttpServer, 0, 2), - } - beeAdminApp = &adminApp{ - HttpServer: NewHttpServerWithCfg(*BConfig), - } - // keep in mind that all data should be html escaped to avoid XSS attack - beeAdminApp.Router("/", c, "get:AdminIndex") - beeAdminApp.Router("/qps", c, "get:QpsIndex") - beeAdminApp.Router("/prof", c, "get:ProfIndex") - beeAdminApp.Router("/healthcheck", c, "get:Healthcheck") - beeAdminApp.Router("/task", c, "get:TaskStatus") - beeAdminApp.Router("/listconf", c, "get:ListConf") - beeAdminApp.Router("/metrics", c, "get:PrometheusMetrics") + FilterMonitorFunc = func(string, string, time.Duration, string, int) bool { return true } - beeAdminApp.Run() } func list(root string, p interface{}, m M) { @@ -110,11 +96,28 @@ func (admin *adminApp) Run() { } logs.Info("Admin server Running on %s", addr) + admin.HttpServer.Run(addr) } func registerAdmin() error { if BConfig.Listen.EnableAdmin { + + c := &adminController{ + servers: make([]*HttpServer, 0, 2), + } + beeAdminApp = &adminApp{ + HttpServer: NewHttpServerWithCfg(*BConfig), + } + // keep in mind that all data should be html escaped to avoid XSS attack + beeAdminApp.Router("/", c, "get:AdminIndex") + beeAdminApp.Router("/qps", c, "get:QpsIndex") + beeAdminApp.Router("/prof", c, "get:ProfIndex") + beeAdminApp.Router("/healthcheck", c, "get:Healthcheck") + beeAdminApp.Router("/task", c, "get:TaskStatus") + beeAdminApp.Router("/listconf", c, "get:ListConf") + beeAdminApp.Router("/metrics", c, "get:PrometheusMetrics") + go beeAdminApp.Run() } return nil diff --git a/pkg/server/web/config.go b/pkg/server/web/config.go index add81b8c..bc46b20e 100644 --- a/pkg/server/web/config.go +++ b/pkg/server/web/config.go @@ -41,7 +41,7 @@ type Config struct { RouterCaseSensitive bool ServerName string RecoverPanic bool - RecoverFunc func(*context.Context) + RecoverFunc func(*context.Context, *Config) CopyRequestBody bool EnableGzip bool MaxMemory int64 @@ -169,7 +169,7 @@ func init() { } } -func (cfg *Config) defaultRecoverPanic(ctx *context.Context) { +func defaultRecoverPanic(ctx *context.Context, cfg *Config) { if err := recover(); err != nil { if err == ErrAbort { return @@ -281,7 +281,7 @@ func newBConfig() *Config { }, } - res.RecoverFunc = res.defaultRecoverPanic + res.RecoverFunc = defaultRecoverPanic return res } diff --git a/pkg/server/web/router.go b/pkg/server/web/router.go index 1a0183bd..a9d1b0cf 100644 --- a/pkg/server/web/router.go +++ b/pkg/server/web/router.go @@ -155,6 +155,7 @@ func NewControllerRegisterWithCfg(cfg *Config) *ControllerRegister { return beecontext.NewContext() }, }, + cfg: cfg, } res.chainRoot = newFilterRouter("/*", res.serveHttp, WithCaseSensitive(false)) return res @@ -678,7 +679,7 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) { ) if p.cfg.RecoverFunc != nil { - defer p.cfg.RecoverFunc(ctx) + defer p.cfg.RecoverFunc(ctx, p.cfg) } ctx.Output.EnableGzip = p.cfg.EnableGzip diff --git a/pkg/server/web/server.go b/pkg/server/web/server.go index 2e91e33c..7bd9023d 100644 --- a/pkg/server/web/server.go +++ b/pkg/server/web/server.go @@ -266,10 +266,6 @@ func (app *HttpServer) Run(addr string, mws ...MiddleWare) { <-endRunning } -func (app *HttpServer) Start() { - -} - // Router see HttpServer.Router func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *HttpServer { return BeeApp.Router(rootpath, c, mappingMethods...)