Allow direct IP access without reverse proxy

This commit is contained in:
2026-05-03 13:17:49 +08:00
parent e98e780360
commit 01027af5bd
2 changed files with 7 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ package middleware
import (
"net"
"net/http"
"strings"
"github.com/gin-gonic/gin"
@@ -15,8 +14,10 @@ func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
host, _, _ = net.SplitHostPort(c.Request.Host)
}
if host != domain {
c.AbortWithStatus(http.StatusForbidden)
// Allow direct IP access even when a domain is configured.
// This keeps domain-based access working while removing the hard reverse-proxy-only restriction.
if host != domain && net.ParseIP(host) == nil {
c.AbortWithStatus(403)
return
}