From d909adb6faeb890fd28f408018eb39f701e8ce95 Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Tue, 26 Aug 2025 20:44:56 +0900 Subject: [PATCH] Moved permanently redirects --- http/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/http/main.go b/http/main.go index 912ae87..8c8f161 100644 --- a/http/main.go +++ b/http/main.go @@ -4,6 +4,7 @@ import ( "encoding/gob" "log" "net/http" + "strings" lishwist "lishwist/core" "lishwist/http/api" @@ -13,6 +14,13 @@ import ( "lishwist/http/session" ) +func prefixMovedPermanently(before, after string) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + suffix := strings.TrimPrefix(r.RequestURI, before) + http.Redirect(w, r, after+suffix, http.StatusMovedPermanently) + } +} + func main() { gob.Register(&api.RegisterProps{}) gob.Register(&api.LoginProps{}) @@ -50,10 +58,8 @@ func main() { r.Private.HandleFunc("POST /{$}", routing.ExpectAppSession(routing.HomePost)) // Deprecated - r.Private.HandleFunc("GET /group/{groupReference}", routing.ExpectAppSession(routing.Group)) - r.Private.HandleFunc("GET /list/{userReference}", routing.ExpectAppSession(routing.ForeignWishlist)) - r.Public.HandleFunc("GET /group/{groupReference}", routing.PublicGroup) - r.Public.HandleFunc("GET /list/{userReference}", routing.PublicWishlist) + http.Handle("GET /group/{groupReference}", prefixMovedPermanently("/group/", "/groups/")) + http.Handle("GET /list/{userReference}", prefixMovedPermanently("/list/", "/lists/")) http.Handle("/", r)