add some more logging so i can see where stuff is failing

This commit is contained in:
Ben Harris 2022-05-26 11:33:17 -04:00
parent 1d8f45ea99
commit 3e04412113
4 changed files with 13 additions and 3 deletions

View File

@ -89,6 +89,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
branchTimestampResult := upstream.GetBranchTimestamp(targetOwner, repo, branch, giteaRoot, giteaAPIToken, branchTimestampCache)
if branchTimestampResult == nil {
// branch doesn't exist
log.Debug().Msgf("branch %s doesn't exist for %s/%s", branch, targetOwner, repo)
return false
}
@ -111,7 +112,8 @@ func Handler(mainDomainSuffix, rawDomain []byte,
return true
}
log.Debug().Msg("preparations")
log.Debug().Msgf("host %s, domain %s", trimmedHost, rawDomain)
if rawDomain != nil && bytes.Equal(trimmedHost, rawDomain) {
// Serve raw content from RawDomain
log.Debug().Msg("raw domain")
@ -168,7 +170,6 @@ func Handler(mainDomainSuffix, rawDomain []byte,
targetPath = strings.Trim(strings.Join(pathElements[1:], "/"), "/")
if targetOwner == "www" {
// www.codeberg.page redirects to codeberg.page // TODO: rm hardcoded - use cname?
ctx.Redirect("https://"+string(mainDomainSuffix[1:])+string(ctx.Path()), fasthttp.StatusPermanentRedirect)
return
}

View File

@ -6,6 +6,7 @@ import (
"path"
"time"
"github.com/rs/zerolog/log"
"github.com/valyala/fasthttp"
"github.com/valyala/fastjson"
)
@ -54,6 +55,7 @@ func giteaGetRepoDefaultBranch(giteaRoot, repoOwner, repoName, giteaAPIToken str
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName))
log.Debug().Msgf("trying repo %s/%s", repoOwner, repoName)
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res := fasthttp.AcquireResponse()

View File

@ -1,6 +1,7 @@
package upstream
import (
"github.com/rs/zerolog/log"
"time"
"codeberg.org/codeberg/pages/server/cache"
@ -14,6 +15,8 @@ type branchTimestamp struct {
// GetBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch
// (or nil if the branch doesn't exist)
func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaAPIToken string, branchTimestampCache cache.SetGetKey) *branchTimestamp {
log.Debug().Msgf("looking up timestamp for %s/%s %s branch", owner, repo, branch)
if result, ok := branchTimestampCache.Get(owner + "/" + repo + "/" + branch); ok {
if result == nil {
return nil
@ -27,6 +30,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaAPIToken string, br
// Get default branch
defaultBranch, err := giteaGetRepoDefaultBranch(giteaRoot, owner, repo, giteaAPIToken)
if err != nil {
log.Err(err)
_ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout)
return nil
}
@ -35,6 +39,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaAPIToken string, br
timestamp, err := giteaGetRepoBranchTimestamp(giteaRoot, owner, repo, branch, giteaAPIToken)
if err != nil {
log.Err(err)
return nil
}
result.Timestamp = timestamp

View File

@ -55,6 +55,8 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaRoot, giteaAPIToken st
o.ForbiddenMimeTypes = map[string]struct{}{}
}
log.Debug().Msgf("owner %s, repo %s, branch %s", o.TargetOwner, o.TargetRepo, o.TargetBranch)
// Check if the branch exists and when it was modified
if o.BranchTimestamp.IsZero() {
branch := GetBranchTimestamp(o.TargetOwner, o.TargetRepo, o.TargetBranch, giteaRoot, giteaAPIToken, branchTimestampCache)
@ -79,7 +81,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaRoot, giteaAPIToken st
return true
}
}
log.Debug().Msg("preparations")
log.Debug().Msg("preparations (in upstream.go)")
// Make a GET request to the upstream URL
uri := path.Join(o.TargetOwner, o.TargetRepo, "raw", o.TargetBranch, o.TargetPath)