feat(pages): Route custom domains to landing page
Some checks failed
Build and Release / Build Binaries (amd64, darwin) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux) (push) Has been skipped
Build and Release / Build Binaries (amd64, windows) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux) (push) Has been skipped
Build and Release / Create Release (push) Has been skipped
Build and Release / Lint (push) Failing after 3s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 48s
Build and Release / Unit Tests (push) Successful in 2m4s

Custom domains configured in Pages settings now route directly
to the repository landing page, in addition to subdomain routing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
David H Friedel Jr 2026-01-11 00:55:11 +00:00
parent e57b4f1654
commit d44fea18d5

View File

@ -8,6 +8,7 @@ import (
"strings"
auth_model "code.gitea.io/gitea/models/auth"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
@ -302,7 +303,7 @@ var optSignInFromAnyOrigin = verifyAuthWithOptions(&common.VerifyOptions{Disable
// registerWebRoutes register routes
func registerWebRoutes(m *web.Router) {
// Check for Pages subdomain requests first
// Check for Pages subdomain and custom domain requests first
m.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
host := req.Host
@ -310,6 +311,7 @@ func registerWebRoutes(m *web.Router) {
if idx := strings.Index(host, ":"); idx > 0 {
host = host[:idx]
}
// Check if this is a subdomain of our main domain
mainDomain := setting.Domain
if strings.HasSuffix(host, "."+mainDomain) {
@ -324,6 +326,17 @@ func registerWebRoutes(m *web.Router) {
return
}
}
} else if host != mainDomain && host != "www."+mainDomain {
// Check if this is a custom domain for Pages
domain, err := repo_model.GetPagesDomainByDomain(req.Context(), host)
if err == nil && domain != nil && domain.Verified {
ctx := context.GetWebContext(req.Context())
if ctx != nil {
log.Trace("Pages custom domain request: %s -> repo %d", host, domain.RepoID)
pages.ServeLandingPage(ctx)
return
}
}
}
next.ServeHTTP(w, req)
})