This commit is contained in:
lbenedar
2026-03-05 14:07:16 +03:00
parent 7ab49c9fc8
commit 5e98af52fe
5 changed files with 23 additions and 13 deletions

View File

@@ -3,20 +3,26 @@ package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/justinas/alice"
)
func (app *application) routes() http.Handler {
mux := http.NewServeMux()
router := httprouter.New()
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.notFound(w)
})
fileServer := http.FileServer(http.Dir("./ui/static/"))
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
router.Handler(http.MethodGet, "/static/", http.StripPrefix("/static", fileServer))
mux.HandleFunc("/", app.home)
mux.HandleFunc("/snippet/view", app.snippetView)
mux.HandleFunc("/snippet/create", app.snippetCreate)
router.HandlerFunc(http.MethodGet, "/", app.home)
router.HandlerFunc(http.MethodGet, "/snippet/view/:id", app.snippetView)
router.HandlerFunc(http.MethodGet, "/snippet/create", app.snippetCreate)
router.HandlerFunc(http.MethodPost, "/snippet/create", app.snippetCreatePost)
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
return standard.Then(mux)
return standard.Then(router)
}