Fix 4435: panic when controllers package not found
This commit is contained in:
@@ -108,8 +108,11 @@ func registerAdmin() error {
|
||||
c := &adminController{
|
||||
servers: make([]*HttpServer, 0, 2),
|
||||
}
|
||||
|
||||
// copy config to avoid conflict
|
||||
adminCfg := *BConfig
|
||||
beeAdminApp = &adminApp{
|
||||
HttpServer: NewHttpServerWithCfg(BConfig),
|
||||
HttpServer: NewHttpServerWithCfg(&adminCfg),
|
||||
}
|
||||
// keep in mind that all data should be html escaped to avoid XSS attack
|
||||
beeAdminApp.Router("/", c, "get:AdminIndex")
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/coreos/etcd/pkg/fileutil"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
"github.com/beego/beego/v2/server/web/session"
|
||||
@@ -98,7 +100,12 @@ func registerGzip() error {
|
||||
|
||||
func registerCommentRouter() error {
|
||||
if BConfig.RunMode == DEV {
|
||||
if err := parserPkg(filepath.Join(WorkPath, BConfig.WebConfig.CommentRouterPath)); err != nil {
|
||||
ctrlDir := filepath.Join(WorkPath, BConfig.WebConfig.CommentRouterPath)
|
||||
if !fileutil.Exist(ctrlDir) {
|
||||
logs.Warn("controller package not found, won't generate router: ", ctrlDir)
|
||||
return nil
|
||||
}
|
||||
if err := parserPkg(ctrlDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user