diff --git a/cmd/rio/main.go b/cmd/rio/main.go index 4e18dc3..aa6e170 100644 --- a/cmd/rio/main.go +++ b/cmd/rio/main.go @@ -67,6 +67,16 @@ func Handler(pagesDomain, giteaUrl, defaultCsp string, giteaClient *repo.GiteaCl return func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Server", "rio") + // Is the direct domain requested? + if req.Host == pagesDomain { + log.Debug("Direct pages domain is requested.") + + // TODO: Handle + w.WriteHeader(404) + return + } + + // Is a direct subdomain requested? if strings.HasSuffix(req.Host, pagesDomain) { log.Debug("Domain can be directly handled") handleSubdomain(req.Host, "", req.URL.Path, giteaUrl, defaultCsp, giteaClient, w) @@ -81,7 +91,10 @@ func Handler(pagesDomain, giteaUrl, defaultCsp string, giteaClient *repo.GiteaCl } log.Debugf("Got CNAME %s", cname) - if strings.HasSuffix(cname, pagesDomain) { + // Is a direct subdomain requested after CNAME lookup? + // NOTE: We now require the leading dot because a CNAME to the direct + // pages domain makes no sense. + if strings.HasSuffix(cname, "."+pagesDomain) { log.Debugf("%s is alias of %s and can be handled after a CNAME query", req.Host, cname) handleSubdomain(req.Host, cname, req.URL.Path, giteaUrl, defaultCsp, giteaClient, w) return