remove use of rawInfoPage redirect (#261)

closes #244

Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/261
Co-authored-by: crapStone <crapstone01@gmail.com>
Co-committed-by: crapStone <crapstone01@gmail.com>
This commit is contained in:
crapStone 2023-11-16 17:33:39 +00:00 committed by crapStone
parent cbb2ce6d07
commit fffb8ffcb6
5 changed files with 8 additions and 15 deletions

View File

@ -72,13 +72,6 @@ var (
EnvVars: []string{"RAW_DOMAIN"}, EnvVars: []string{"RAW_DOMAIN"},
Value: "raw.codeberg.page", Value: "raw.codeberg.page",
}, },
// RawInfoPage will be shown (with a redirect) when trying to access RawDomain directly (or without owner/repo/path).
&cli.StringFlag{
Name: "raw-info-page",
Usage: "will be shown (with a redirect) when trying to access $RAW_DOMAIN directly (or without owner/repo/path)",
EnvVars: []string{"RAW_INFO_PAGE"},
Value: "https://docs.codeberg.org/codeberg-pages/raw-content/",
},
// ######################### // #########################
// ### Page Server Setup ### // ### Page Server Setup ###

View File

@ -47,7 +47,6 @@ func Serve(ctx *cli.Context) error {
rawDomain := ctx.String("raw-domain") rawDomain := ctx.String("raw-domain")
defaultBranches := ctx.StringSlice("pages-branch") defaultBranches := ctx.StringSlice("pages-branch")
mainDomainSuffix := ctx.String("pages-domain") mainDomainSuffix := ctx.String("pages-domain")
rawInfoPage := ctx.String("raw-info-page")
listeningHost := ctx.String("host") listeningHost := ctx.String("host")
listeningSSLPort := ctx.Uint("port") listeningSSLPort := ctx.Uint("port")
listeningSSLAddress := fmt.Sprintf("%s:%d", listeningHost, listeningSSLPort) listeningSSLAddress := fmt.Sprintf("%s:%d", listeningHost, listeningSSLPort)
@ -137,7 +136,6 @@ func Serve(ctx *cli.Context) error {
// Create ssl handler based on settings // Create ssl handler based on settings
sslHandler := handler.Handler(mainDomainSuffix, rawDomain, sslHandler := handler.Handler(mainDomainSuffix, rawDomain,
giteaClient, giteaClient,
rawInfoPage,
BlacklistedPaths, allowedCorsDomains, BlacklistedPaths, allowedCorsDomains,
defaultBranches, defaultBranches,
dnsLookupCache, canonicalDomainCache, redirectsCache) dnsLookupCache, canonicalDomainCache, redirectsCache)

View File

@ -21,7 +21,6 @@ const (
// Handler handles a single HTTP request to the web server. // Handler handles a single HTTP request to the web server.
func Handler(mainDomainSuffix, rawDomain string, func Handler(mainDomainSuffix, rawDomain string,
giteaClient *gitea.Client, giteaClient *gitea.Client,
rawInfoPage string,
blacklistedPaths, allowedCorsDomains []string, blacklistedPaths, allowedCorsDomains []string,
defaultPagesBranches []string, defaultPagesBranches []string,
dnsLookupCache, canonicalDomainCache, redirectsCache cache.SetGetKey, dnsLookupCache, canonicalDomainCache, redirectsCache cache.SetGetKey,
@ -89,7 +88,7 @@ func Handler(mainDomainSuffix, rawDomain string,
if rawDomain != "" && strings.EqualFold(trimmedHost, rawDomain) { if rawDomain != "" && strings.EqualFold(trimmedHost, rawDomain) {
log.Debug().Msg("raw domain request detected") log.Debug().Msg("raw domain request detected")
handleRaw(log, ctx, giteaClient, handleRaw(log, ctx, giteaClient,
mainDomainSuffix, rawInfoPage, mainDomainSuffix,
trimmedHost, trimmedHost,
pathElements, pathElements,
canonicalDomainCache, redirectsCache) canonicalDomainCache, redirectsCache)

View File

@ -16,7 +16,7 @@ import (
) )
func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client, func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client,
mainDomainSuffix, rawInfoPage string, mainDomainSuffix string,
trimmedHost string, trimmedHost string,
pathElements []string, pathElements []string,
canonicalDomainCache, redirectsCache cache.SetGetKey, canonicalDomainCache, redirectsCache cache.SetGetKey,
@ -25,8 +25,12 @@ func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Clie
log.Debug().Msg("raw domain") log.Debug().Msg("raw domain")
if len(pathElements) < 2 { if len(pathElements) < 2 {
// https://{RawDomain}/{owner}/{repo}[/@{branch}]/{path} is required html.ReturnErrorPage(
ctx.Redirect(rawInfoPage, http.StatusTemporaryRedirect) ctx,
"a url in the form of <code>https://{domain}/{owner}/{repo}[/@{branch}]/{path}</code> is required",
http.StatusBadRequest,
)
return return
} }

View File

@ -16,7 +16,6 @@ func TestHandlerPerformance(t *testing.T) {
testHandler := Handler( testHandler := Handler(
"codeberg.page", "raw.codeberg.org", "codeberg.page", "raw.codeberg.org",
giteaClient, giteaClient,
"https://docs.codeberg.org/pages/raw-content/",
[]string{"/.well-known/acme-challenge/"}, []string{"/.well-known/acme-challenge/"},
[]string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"}, []string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"},
[]string{"pages"}, []string{"pages"},