mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
Merge branch 'main' into issue115
This commit is contained in:
commit
9a48680948
1 changed files with 7 additions and 5 deletions
|
@ -15,6 +15,8 @@ import (
|
||||||
"codeberg.org/codeberg/pages/server/upstream"
|
"codeberg.org/codeberg/pages/server/upstream"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultPagesRepo = "pages"
|
||||||
|
|
||||||
func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client,
|
func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client,
|
||||||
mainDomainSuffix string,
|
mainDomainSuffix string,
|
||||||
defaultPagesBranches []string,
|
defaultPagesBranches []string,
|
||||||
|
@ -37,7 +39,7 @@ func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gite
|
||||||
// Check if the first directory is a repo with the second directory as a branch
|
// Check if the first directory is a repo with the second directory as a branch
|
||||||
// example.codeberg.page/myrepo/@main/index.html
|
// example.codeberg.page/myrepo/@main/index.html
|
||||||
if len(pathElements) > 1 && strings.HasPrefix(pathElements[1], "@") {
|
if len(pathElements) > 1 && strings.HasPrefix(pathElements[1], "@") {
|
||||||
if targetRepo == "pages" {
|
if targetRepo == defaultPagesRepo {
|
||||||
// example.codeberg.org/pages/@... redirects to example.codeberg.org/@...
|
// example.codeberg.org/pages/@... redirects to example.codeberg.org/@...
|
||||||
ctx.Redirect("/"+strings.Join(pathElements[1:], "/"), http.StatusTemporaryRedirect)
|
ctx.Redirect("/"+strings.Join(pathElements[1:], "/"), http.StatusTemporaryRedirect)
|
||||||
return
|
return
|
||||||
|
@ -61,14 +63,14 @@ func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gite
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the first directory is a branch for the "pages" repo
|
// Check if the first directory is a branch for the defaultPagesRepo
|
||||||
// example.codeberg.page/@main/index.html
|
// example.codeberg.page/@main/index.html
|
||||||
if strings.HasPrefix(pathElements[0], "@") {
|
if strings.HasPrefix(pathElements[0], "@") {
|
||||||
log.Debug().Msg("main domain preparations, now trying with specified branch")
|
log.Debug().Msg("main domain preparations, now trying with specified branch")
|
||||||
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
|
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
|
||||||
TryIndexPages: true,
|
TryIndexPages: true,
|
||||||
TargetOwner: targetOwner,
|
TargetOwner: targetOwner,
|
||||||
TargetRepo: "pages",
|
TargetRepo: defaultPagesRepo,
|
||||||
TargetBranch: pathElements[0][1:],
|
TargetBranch: pathElements[0][1:],
|
||||||
TargetPath: path.Join(pathElements[1:]...),
|
TargetPath: path.Join(pathElements[1:]...),
|
||||||
}, true); works {
|
}, true); works {
|
||||||
|
@ -101,13 +103,13 @@ func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to use the "pages" repo on its default branch
|
// Try to use the defaultPagesRepo on its default branch
|
||||||
// example.codeberg.page/index.html
|
// example.codeberg.page/index.html
|
||||||
log.Debug().Msg("main domain preparations, now trying with default repo/branch")
|
log.Debug().Msg("main domain preparations, now trying with default repo/branch")
|
||||||
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
|
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
|
||||||
TryIndexPages: true,
|
TryIndexPages: true,
|
||||||
TargetOwner: targetOwner,
|
TargetOwner: targetOwner,
|
||||||
TargetRepo: branch,
|
TargetRepo: defaultPagesRepo,
|
||||||
TargetPath: path.Join(pathElements...),
|
TargetPath: path.Join(pathElements...),
|
||||||
}, false); works {
|
}, false); works {
|
||||||
log.Debug().Msg("tryBranch, now trying upstream 6")
|
log.Debug().Msg("tryBranch, now trying upstream 6")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue