learn-go/snippetbox/cmd/web/routes.go
tamsin johnson 4f2dc018da lets-go:11.0 user signup without peeking
deliberately skipping salting and encrypting passwords at this point. intending
to approach this in tandem with authenication.

also starting to want db migrations, but trying not to get distracted.
2024-02-07 11:07:29 -08:00

41 lines
1.4 KiB
Go

package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/justinas/alice"
)
// routes ...
func (app *application) routes() http.Handler {
router := httprouter.New()
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.notFound(w)
})
router.MethodNotAllowed = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.clientError(w, http.StatusMethodNotAllowed)
})
// setup server for static files
fileServer := http.FileServer(http.Dir("./ui/static"))
router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))
dynamic := alice.New(app.sessionManager.LoadAndSave)
router.Handler(http.MethodGet, "/", dynamic.ThenFunc(app.home))
router.Handler(http.MethodGet, "/snippet/view/:id", dynamic.ThenFunc(app.snippetView))
router.Handler(http.MethodGet, "/snippet/create", dynamic.ThenFunc(app.snippetCreate))
router.Handler(http.MethodPost, "/snippet/create", dynamic.ThenFunc(app.snippetCreatePost))
router.Handler(http.MethodGet, "/user/signup", dynamic.ThenFunc(app.userSignup))
router.Handler(http.MethodPost, "/user/signup", dynamic.ThenFunc(app.userSignupPost))
// router.Handler(http.MethodGet, "/user/login", dynamic.ThenFunc(app.userLogin))
// router.Handler(http.MethodPost, "/user/login", dynamic.ThenFunc(app.userLoginPost))
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
return standard.Then(router)
}