From 28e7e769b1bb5ba5fc999237c3984bf3205d425e Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 5 May 2020 19:30:28 +1200 Subject: [PATCH] support redirecting project alternative names --- config.toml.sample | 3 +++ main.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/config.toml.sample b/config.toml.sample index d67150a..aa4f0dd 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -6,6 +6,9 @@ BindTo="0.0.0.0:5656" URL="https://gitea.com/" Org="gitea" +[Redirect] +"old-project-name" = "new-project-name" + [Template] AppName = "Teafolio" diff --git a/main.go b/main.go index 7282f47..e12884a 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ type Config struct { Gitea struct { URL, Org string } + Redirect map[string]string Template struct { AppName string HomepageHeaderHTML string @@ -308,6 +309,13 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + // Maybe it's a redirected project (alternative name) + if rename, ok := this.cfg.Redirect[repoName]; ok { + w.Header().Set(`Location`, `/`+url.PathEscape(rename)) + w.WriteHeader(301) + return + } + this.Repopage(w, r, repoName) } else if r.URL.Path == `/static/logo.png` {