From d44fea18d53785dfb8ef747ac8ebf2c1982cebbd Mon Sep 17 00:00:00 2001 From: Admin Date: Sun, 11 Jan 2026 00:55:11 +0000 Subject: [PATCH] feat(pages): Route custom domains to landing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- routers/web/web.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/routers/web/web.go b/routers/web/web.go index 7e5ac5173a..ac3c315d77 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -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) })