diff --git a/cmd/flags.go b/cmd/flags.go index a71dd35..7ac94e6 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -72,13 +72,6 @@ var ( EnvVars: []string{"RAW_DOMAIN"}, 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 ### diff --git a/cmd/main.go b/cmd/main.go index 84915c9..683e859 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -47,7 +47,6 @@ func Serve(ctx *cli.Context) error { rawDomain := ctx.String("raw-domain") defaultBranches := ctx.StringSlice("pages-branch") mainDomainSuffix := ctx.String("pages-domain") - rawInfoPage := ctx.String("raw-info-page") listeningHost := ctx.String("host") listeningSSLPort := ctx.Uint("port") listeningSSLAddress := fmt.Sprintf("%s:%d", listeningHost, listeningSSLPort) @@ -137,7 +136,6 @@ func Serve(ctx *cli.Context) error { // Create ssl handler based on settings sslHandler := handler.Handler(mainDomainSuffix, rawDomain, giteaClient, - rawInfoPage, BlacklistedPaths, allowedCorsDomains, defaultBranches, dnsLookupCache, canonicalDomainCache, redirectsCache) diff --git a/server/handler/handler.go b/server/handler/handler.go index a3011f3..7da5d39 100644 --- a/server/handler/handler.go +++ b/server/handler/handler.go @@ -21,7 +21,6 @@ const ( // Handler handles a single HTTP request to the web server. func Handler(mainDomainSuffix, rawDomain string, giteaClient *gitea.Client, - rawInfoPage string, blacklistedPaths, allowedCorsDomains []string, defaultPagesBranches []string, dnsLookupCache, canonicalDomainCache, redirectsCache cache.SetGetKey, @@ -89,7 +88,7 @@ func Handler(mainDomainSuffix, rawDomain string, if rawDomain != "" && strings.EqualFold(trimmedHost, rawDomain) { log.Debug().Msg("raw domain request detected") handleRaw(log, ctx, giteaClient, - mainDomainSuffix, rawInfoPage, + mainDomainSuffix, trimmedHost, pathElements, canonicalDomainCache, redirectsCache) diff --git a/server/handler/handler_raw_domain.go b/server/handler/handler_raw_domain.go index b87991e..caa8209 100644 --- a/server/handler/handler_raw_domain.go +++ b/server/handler/handler_raw_domain.go @@ -16,7 +16,7 @@ import ( ) func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client, - mainDomainSuffix, rawInfoPage string, + mainDomainSuffix string, trimmedHost string, pathElements []string, canonicalDomainCache, redirectsCache cache.SetGetKey, @@ -25,8 +25,12 @@ func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Clie log.Debug().Msg("raw domain") if len(pathElements) < 2 { - // https://{RawDomain}/{owner}/{repo}[/@{branch}]/{path} is required - ctx.Redirect(rawInfoPage, http.StatusTemporaryRedirect) + html.ReturnErrorPage( + ctx, + "a url in the form of https://{domain}/{owner}/{repo}[/@{branch}]/{path} is required", + http.StatusBadRequest, + ) + return } diff --git a/server/handler/handler_test.go b/server/handler/handler_test.go index 6521633..d04ebda 100644 --- a/server/handler/handler_test.go +++ b/server/handler/handler_test.go @@ -16,7 +16,6 @@ func TestHandlerPerformance(t *testing.T) { testHandler := Handler( "codeberg.page", "raw.codeberg.org", giteaClient, - "https://docs.codeberg.org/pages/raw-content/", []string{"/.well-known/acme-challenge/"}, []string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"}, []string{"pages"},