Wildcards #2
@ -26,8 +26,10 @@ import (
|
||||
func handleSubdomain(domain, cname, path, giteaUrl, defaultCsp string, giteaClient *repo.GiteaClient, w http.ResponseWriter) {
|
||||
username := ""
|
||||
if cname != "" {
|
||||
// If we are accessed via a CNAME, then CNAME contains our <user>.<pages domain> value.
|
||||
username = strings.Split(cname, ".")[0]
|
||||
} else {
|
||||
// If we are directly accessed, then domain contains our <user>.<pages domain> value.
|
||||
username = strings.Split(domain, ".")[0]
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,6 @@ func makeCSPCacheKey(username, repositoryName string) string {
|
||||
return username + ":" + repositoryName
|
||||
}
|
||||
|
||||
// / Try to find the repository with name @reponame of the user @username. If @cname
|
||||
// / is not "", then it also verifies that the repository contains a "CNAME" with
|
||||
// / the value of @cname as its content. @host, @domain, and @path are passed for
|
||||
// / caching on success.
|
||||
func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path, cname string, giteaClient *GiteaClient) (*Repository, error) {
|
||||
log.Debugf("CNAME: %s", cname)
|
||||
log.Debugf("Looking up repository %s/%s", username, reponame)
|
||||
@ -85,8 +81,8 @@ func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path
|
||||
)
|
||||
|
||||
log.Debugf("CNAME Content: %s", cnameContent)
|
||||
if cnameContent != cname {
|
||||
log.Warnf("CNAME mismatch: Repo '%s', CNAME '%s'", cnameContent, cname)
|
||||
if cnameContent != host {
|
||||
log.Warnf("CNAME mismatch: Repo '%s', Host '%s'", cnameContent, host)
|
||||
return nil, errors.New("CNAME mismatch")
|
||||
}
|
||||
}
|
||||
@ -103,6 +99,8 @@ func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path
|
||||
return &repo, nil
|
||||
}
|
||||
|
||||
// host is the domain name we're accessed from. cname is the domain that host is pointing
|
||||
// if, if we're accessed via a CNAME. If not, then cname is "".
|
||||
func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient) (*Repository, string, error) {
|
||||
domain := host
|
||||
|
||||
@ -117,11 +115,11 @@ func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient)
|
||||
// Allow specifying the repository name in the TXT record
|
||||
reponame := ""
|
||||
if cname != "" {
|
||||
repoLookup, err := giteaClient.lookupRepoTXT(cname)
|
||||
repoLookup, err := giteaClient.lookupRepoTXT(host)
|
||||
if err == nil && repoLookup != "" {
|
||||
log.Infof(
|
||||
"TXT lookup for %s resulted in choosing repository %s",
|
||||
cname,
|
||||
host,
|
||||
repoLookup,
|
||||
)
|
||||
reponame = repoLookup
|
||||
|
Loading…
Reference in New Issue
Block a user