package base import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" "net/http" config2 "nginx-ui/server/config" "nginx-ui/server/models" "strings" ) type ErrorController struct { beego.Controller WebPath string } func getWebPath() string { config := config2.Config p := config.ContextPath if !strings.HasPrefix(p, "/") { p = "/" + p } if !strings.HasSuffix(p, "/") { p = p + "/" } return p } func (c *ErrorController) Error404() { if c.WebPath == "" { c.WebPath = getWebPath() } request := c.Ctx.Request accept := request.Header.Get("accept") logs.Warn("404", accept) if strings.Contains(accept, "json") { c.Data["json"] = models.RespData{ Code: -2, Msg: "server error", } c.ServeJSON() } else if c.WebPath != request.RequestURI { c.Redirect(c.WebPath, http.StatusMovedPermanently) } else { c.Data["json"] = models.RespData{ Code: 404, Msg: "Not Found", } c.ServeJSON() } }