From fedfa8def462dc14f32b85a0556af36dd2f2c633 Mon Sep 17 00:00:00 2001 From: Moritz Marquardt Date: Wed, 1 Dec 2021 22:59:38 +0100 Subject: [PATCH] Remove REDIRECT_BROKEN_DNS page and instead use "Failed Dependency" error --- README.md | 1 - handler.go | 4 ++-- main.go | 3 --- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b6b1b98..35c230e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ - `RAW_DOMAIN` (default: `raw.codeberg.org`): domain for raw resources. - `GITEA_ROOT` (default: `https://codeberg.org`): root of the upstream Gitea instance. - `GITEA_API_TOKEN` (default: empty): API token for the Gitea instance to access non-public (e.g. limited) repos. -- `REDIRECT_BROKEN_DNS` (default: https://docs.codeberg.org/pages/custom-domains/): info page for setting up DNS, shown for invalid DNS setups. - `REDIRECT_RAW_INFO` (default: https://docs.codeberg.org/pages/raw-content/): info page for raw resources, shown if no resource is provided. - `ACME_API` (default: https://acme-v02.api.letsencrypt.org/directory): set this to https://acme.mock.director to use invalid certificates without any verification (great for debugging). ZeroSSL might be better in the future as it doesn't have rate limits and doesn't clash with the official Codeberg certificates (which are using Let's Encrypt), but I couldn't get it to work yet. diff --git a/handler.go b/handler.go index a731412..f563b14 100644 --- a/handler.go +++ b/handler.go @@ -242,7 +242,7 @@ func handler(ctx *fasthttp.RequestCtx) { // Serve pages from external domains targetOwner, targetRepo, targetBranch = getTargetFromDNS(trimmedHostStr) if targetOwner == "" { - ctx.Redirect(BrokenDNSPage, fasthttp.StatusTemporaryRedirect) + returnErrorPage(ctx, fasthttp.StatusFailedDependency) return } @@ -268,7 +268,7 @@ func handler(ctx *fasthttp.RequestCtx) { ctx.Redirect("https://"+canonicalDomain+string(ctx.RequestURI()), fasthttp.StatusTemporaryRedirect) return } else { - ctx.Redirect(BrokenDNSPage, fasthttp.StatusTemporaryRedirect) + returnErrorPage(ctx, fasthttp.StatusFailedDependency) return } } diff --git a/main.go b/main.go index d6a1d7f..44cec0f 100644 --- a/main.go +++ b/main.go @@ -44,9 +44,6 @@ var GiteaApiToken = envOr("GITEA_API_TOKEN", "") //go:embed 404.html var NotFoundPage []byte -// BrokenDNSPage will be shown (with a redirect) when trying to access a domain for which no DNS CNAME record exists. -var BrokenDNSPage = envOr("REDIRECT_BROKEN_DNS", "https://docs.codeberg.org/pages/custom-domains/") - // RawDomain specifies the domain from which raw repository content shall be served in the following format: // https://{RawDomain}/{owner}/{repo}[/{branch|tag|commit}/{version}]/{filepath...} // (set to []byte(nil) to disable raw content hosting)