appview: support git clones for repo.git urls #797

merged
opened by oppi.li targeting master from op/pzylsqyxzukx

instead of rewriting, simply accept .git suffixes in the ResolveRepo middleware.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+3 -6
appview
middleware
state
+2
appview/middleware/middleware.go
···
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
repoName := chi.URLParam(req, "repo")
+
repoName = strings.TrimSuffix(repoName, ".git")
+
id, ok := req.Context().Value("resolvedId").(identity.Identity)
if !ok {
log.Println("malformed middleware")
+1 -6
appview/state/router.go
···
http.Redirect(w, r, "/"+redirectPath, http.StatusFound)
return
}
+
}
standardRouter.ServeHTTP(w, r)
···
r.Get("/", s.Profile)
r.Get("/feed.atom", s.AtomFeedPage)
-
// redirect /@handle/repo.git -> /@handle/repo
-
r.Get("/{repo}.git", func(w http.ResponseWriter, r *http.Request) {
-
nonDotGitPath := strings.TrimSuffix(r.URL.Path, ".git")
-
http.Redirect(w, r, nonDotGitPath, http.StatusMovedPermanently)
-
})
-
r.With(mw.ResolveRepo()).Route("/{repo}", func(r chi.Router) {
r.Use(mw.GoImport())
r.Mount("/", s.RepoRouter(mw))