Moved permanently redirects

This commit is contained in:
Teajey 2025-08-26 20:44:56 +09:00
parent a1ac719229
commit d909adb6fa
Signed by: Teajey
GPG Key ID: 970E790FE834A713
1 changed files with 10 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/gob" "encoding/gob"
"log" "log"
"net/http" "net/http"
"strings"
lishwist "lishwist/core" lishwist "lishwist/core"
"lishwist/http/api" "lishwist/http/api"
@ -13,6 +14,13 @@ import (
"lishwist/http/session" "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() { func main() {
gob.Register(&api.RegisterProps{}) gob.Register(&api.RegisterProps{})
gob.Register(&api.LoginProps{}) gob.Register(&api.LoginProps{})
@ -50,10 +58,8 @@ func main() {
r.Private.HandleFunc("POST /{$}", routing.ExpectAppSession(routing.HomePost)) r.Private.HandleFunc("POST /{$}", routing.ExpectAppSession(routing.HomePost))
// Deprecated // Deprecated
r.Private.HandleFunc("GET /group/{groupReference}", routing.ExpectAppSession(routing.Group)) http.Handle("GET /group/{groupReference}", prefixMovedPermanently("/group/", "/groups/"))
r.Private.HandleFunc("GET /list/{userReference}", routing.ExpectAppSession(routing.ForeignWishlist)) http.Handle("GET /list/{userReference}", prefixMovedPermanently("/list/", "/lists/"))
r.Public.HandleFunc("GET /group/{groupReference}", routing.PublicGroup)
r.Public.HandleFunc("GET /list/{userReference}", routing.PublicWishlist)
http.Handle("/", r) http.Handle("/", r)