mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/1Panel-dev/1Panel.git
synced 2026-09-20 16:13:59 +08:00
* feat: change isProductPro logic (#12712) * fix: tighten frontend RBAC permission guards (#12717) * fix: tighten frontend RBAC permission guards * feat: add permission directive coverage * refactor frontend global store usage * serve frontend routes with fallback --------- Co-authored-by: CityFun <31820853+zhengkunwang223@users.noreply.github.com>
45 lines
967 B
Go
45 lines
967 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/utils/security"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func FrontendFallback() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if !isFrontendFallbackRequest(c) {
|
|
c.Next()
|
|
return
|
|
}
|
|
if security.CanServeFrontendPath(c) {
|
|
security.ToIndexHtml(c)
|
|
c.Abort()
|
|
return
|
|
}
|
|
security.HandleNotSecurity(c, "")
|
|
c.Abort()
|
|
}
|
|
}
|
|
|
|
func isFrontendFallbackRequest(c *gin.Context) bool {
|
|
if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {
|
|
return false
|
|
}
|
|
path := c.Request.URL.Path
|
|
if strings.HasPrefix(path, "/api/") ||
|
|
strings.HasPrefix(path, "/assets/") ||
|
|
strings.HasPrefix(path, "/public") ||
|
|
strings.HasPrefix(path, "/1panel/swagger/") ||
|
|
path == "/favicon.ico" {
|
|
return false
|
|
}
|
|
if !security.IsFrontendPath(path) {
|
|
return false
|
|
}
|
|
accept := c.GetHeader("Accept")
|
|
return accept == "" || strings.Contains(accept, "text/html")
|
|
}
|