feat: Prevent weird situations if we have no username

This commit is contained in:
PapaTutuWawa 2024-01-11 20:25:50 +01:00
parent 2cbe46dc1a
commit fe2f418e35

View File

@ -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