61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"net/http"
|
|
|
|
"lishwist/http/env"
|
|
"lishwist/http/middleware"
|
|
"lishwist/http/mux"
|
|
"lishwist/http/props"
|
|
"lishwist/http/routing"
|
|
"lishwist/http/session"
|
|
)
|
|
|
|
func Create(useSecureCookies bool) *mux.Serve {
|
|
gob.Register(&props.Register{})
|
|
gob.Register(&props.Login{})
|
|
gob.Register(&routing.AccountProps{})
|
|
|
|
store := session.NewInMemoryStore([]byte(env.Configuration.SessionSecret))
|
|
store.Options.MaxAge = 86_400 // 24 hours in seconds
|
|
store.Options.Secure = useSecureCookies
|
|
store.Options.HttpOnly = true
|
|
store.Options.Path = "/"
|
|
store.Options.SameSite = http.SameSiteLaxMode
|
|
|
|
r := mux.New(store)
|
|
|
|
r.Public.HandleFunc("GET /", routing.Login)
|
|
r.Public.HandleFunc("GET /groups/{groupReference}", routing.PublicGroup)
|
|
r.Public.HandleFunc("GET /lists/{userReference}", routing.PublicWishlist)
|
|
r.Public.HandleFunc("GET /register", routing.Register)
|
|
r.Public.HandleFunc("POST /", routing.LoginPost)
|
|
r.Public.HandleFunc("POST /register", routing.RegisterPost)
|
|
|
|
r.Private.HandleFunc("GET /events", routing.EventList)
|
|
r.Private.HandleFunc("GET /account", routing.Account)
|
|
r.Private.HandleFunc("GET /health", routing.Health)
|
|
r.Private.HandleFunc("GET /", routing.NotFound)
|
|
r.Private.HandleFunc("GET /groups", routing.Groups)
|
|
r.Private.HandleFunc("GET /groups/{groupReference}", routing.Group)
|
|
r.Private.HandleFunc("GET /lists/{userReference}", routing.ForeignWishlist)
|
|
r.Private.HandleFunc("GET /users", routing.Users)
|
|
r.Private.HandleFunc("GET /users/{userReference}", routing.User)
|
|
r.Private.HandleFunc("GET /{$}", routing.Home)
|
|
r.Private.HandleFunc("POST /account", routing.AccountPost)
|
|
r.Private.HandleFunc("POST /groups/{groupReference}", routing.GroupPost)
|
|
r.Private.HandleFunc("POST /lists/{userReference}", routing.ForeignWishlistPost)
|
|
r.Private.HandleFunc("POST /logout", routing.LogoutPost)
|
|
r.Private.HandleFunc("POST /users/{userReference}", routing.UserPost)
|
|
r.Private.HandleFunc("POST /{$}", routing.HomePost)
|
|
|
|
// Deprecated
|
|
r.HandleFunc("GET /group/{groupReference}", middleware.PrefixMovedPermanently("/group/", "/groups/"))
|
|
r.HandleFunc("GET /list/{groupReference}", middleware.PrefixMovedPermanently("/list/", "/lists/"))
|
|
r.HandleFunc("POST /group/{groupReference}", middleware.PrefixPermanentRedirect("/group/", "/groups/"))
|
|
r.HandleFunc("POST /list/{groupReference}", middleware.PrefixPermanentRedirect("/list/", "/lists/"))
|
|
|
|
return r
|
|
}
|