From c4bae34b713182bfaa3970cd5160a84285684055 Mon Sep 17 00:00:00 2001 From: Moritz Marquardt Date: Fri, 19 Mar 2021 13:20:00 +0100 Subject: [PATCH] Add TODOs --- domains.go | 4 ++++ handler.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/domains.go b/domains.go index d0b25b1..c244e40 100644 --- a/domains.go +++ b/domains.go @@ -4,8 +4,12 @@ import "github.com/valyala/fasthttp" // getTargetFromDNS searches for CNAME entries on the request domain, optionally with a "www." prefix, and checks if // the domain is included in the repository's "domains.txt" file. If everything is fine, it returns the target data. +// TODO: use TXT records with A/AAAA/ALIAS func getTargetFromDNS(ctx *fasthttp.RequestCtx) (targetOwner, targetRepo, targetBranch, targetPath string) { // TODO: read CNAME record for host and "www.{host}" to get those values // TODO: check domains.txt return } + +// TODO: cache domains.txt for 15 minutes +// TODO: canonical domains - redirect to first domain if domains.txt exists, also make sure owner.codeberg.page/pages/... redirects to /... diff --git a/handler.go b/handler.go index 97c38ad..be78499 100644 --- a/handler.go +++ b/handler.go @@ -66,6 +66,8 @@ func handler(ctx *fasthttp.RequestCtx) { if RawDomain != nil && bytes.Equal(ctx.Request.Host(), RawDomain) { // Serve raw content from RawDomain + // TODO: add canonical link and "X-Robots-Tag: noarchive, noindex" + targetOptions.TryIndexPages = false targetOptions.ForbiddenMimeTypes["text/html"] = struct{}{} targetOptions.DefaultMimeType = "text/plain; charset=utf-8" @@ -102,6 +104,8 @@ func handler(ctx *fasthttp.RequestCtx) { } else if bytes.HasSuffix(ctx.Request.Host(), MainDomainSuffix) { // Serve pages from subdomains of MainDomainSuffix + // TODO: add @branch syntax with "X-Robots-Tag: noarchive, noindex" + pathElements := strings.SplitN(string(bytes.Trim(ctx.Request.URI().Path(), "/")), "/", 2) targetOwner = string(bytes.TrimSuffix(ctx.Request.Host(), MainDomainSuffix)) targetRepo = pathElements[0] @@ -154,6 +158,7 @@ func returnErrorPage(ctx *fasthttp.RequestCtx, code int) { // getBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch // (or an empty time.Time if the branch doesn't exist) +// TODO: cache responses for ~15 minutes if a branch exists func getBranchTimestamp(owner, repo, branch string) (branchWithFallback string, t time.Time) { branchWithFallback = branch if branch == "" {