|
@@ -1,15 +1,13 @@
|
|
|
package routers
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego"
|
|
|
"github.com/astaxie/beego/context"
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
- "net/http"
|
|
|
+ "nginx-ui/server/base"
|
|
|
config2 "nginx-ui/server/config"
|
|
|
"nginx-ui/server/middleware"
|
|
|
- "nginx-ui/server/models"
|
|
|
"nginx-ui/server/modules/ldap"
|
|
|
"nginx-ui/server/modules/nginx/nginx_controller"
|
|
|
"nginx-ui/server/modules/oauth2"
|
|
@@ -78,25 +76,17 @@ func init() {
|
|
|
beego.Router(fmt.Sprintf("%s/config.js", config.ContextPath), &nginx_controller.ConfigController{})
|
|
|
// portal static assets
|
|
|
beego.SetStaticPath(config.ContextPath, "static/web")
|
|
|
+
|
|
|
+ webPrefix := config.ContextPath
|
|
|
+ if !strings.HasSuffix(webPrefix, "/") {
|
|
|
+ webPrefix = webPrefix + "/"
|
|
|
+ }
|
|
|
+
|
|
|
beego.Get("/", func(ctx *context.Context) {
|
|
|
- ctx.Redirect(301, fmt.Sprintf("%s/index.html", config.ContextPath))
|
|
|
+ ctx.Redirect(301, webPrefix)
|
|
|
})
|
|
|
|
|
|
- beego.ErrorHandler("404", func(writer http.ResponseWriter, request *http.Request) {
|
|
|
- accept := request.Header.Get("accept")
|
|
|
- logs.Warn("404", accept)
|
|
|
- if strings.Contains(accept, "json") {
|
|
|
- writer.Header().Set("content-type", "application/json")
|
|
|
- writer.WriteHeader(200)
|
|
|
- resp := models.RespData{
|
|
|
- Code: -2,
|
|
|
- Msg: "server error",
|
|
|
- }
|
|
|
- str, _ := json.Marshal(&resp)
|
|
|
- writer.Write(str)
|
|
|
- } else {
|
|
|
- writer.WriteHeader(404)
|
|
|
- writer.Write([]byte(""))
|
|
|
- }
|
|
|
+ beego.ErrorController(&base.ErrorController{
|
|
|
+ WebPath: webPrefix,
|
|
|
})
|
|
|
}
|