add middlewares, handlers and database models

This commit is contained in:
juancwu 2025-12-16 10:46:34 -05:00
commit 7e288ea67a
24 changed files with 1045 additions and 14 deletions

View file

@ -12,9 +12,14 @@ import (
func SetupRoutes(a *app.App) http.Handler {
auth := handler.NewAuthHandler()
home := handler.NewHomeHandler()
mux := http.NewServeMux()
// ====================================================================================
// PUBLIC ROUTES
// ====================================================================================
// Static
sub, _ := fs.Sub(assets.AssetsFS, ".")
mux.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(sub))))
@ -22,5 +27,17 @@ func SetupRoutes(a *app.App) http.Handler {
// Auth pages
mux.HandleFunc("GET /auth", middleware.RequireGuest(auth.AuthPage))
return mux
// 404
mux.HandleFunc("/{path...}", home.NotFoundPage)
// Global middlewares
handler := middleware.Chain(
mux,
middleware.Config(a.Cfg),
middleware.RequestLogging,
middleware.CSRFProtection,
middleware.WithURLPath,
)
return handler
}