From 7a264bf0bc1135bc331a57f587ab880dc8a00ed5 Mon Sep 17 00:00:00 2001 From: juancwu <46619361+juancwu@users.noreply.github.com> Date: Mon, 5 Jan 2026 15:23:42 -0500 Subject: [PATCH] add simple / path handler --- internal/handler/home.go | 16 +++++++++++++++- internal/routes/routes.go | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/handler/home.go b/internal/handler/home.go index 9331a4c..50d0ca0 100644 --- a/internal/handler/home.go +++ b/internal/handler/home.go @@ -1,6 +1,10 @@ package handler -import "net/http" +import ( + "net/http" + + "git.juancwu.dev/juancwu/budgit/internal/ctxkeys" +) type homeHandler struct{} @@ -8,6 +12,16 @@ func NewHomeHandler() *homeHandler { return &homeHandler{} } +// HomePage will redirect to /auth if not authenticated or to /app/dashboard if authenticated. +func (h *homeHandler) HomePage(w http.ResponseWriter, r *http.Request) { + user := ctxkeys.User(r.Context()) + if user == nil { + http.Redirect(w, r, "/auth", http.StatusSeeOther) + return + } + http.Redirect(w, r, "/app/dashboard", http.StatusSeeOther) +} + func (home *homeHandler) NotFoundPage(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) w.Write([]byte("404 Page Not Found")) diff --git a/internal/routes/routes.go b/internal/routes/routes.go index 78f17dd..126388a 100644 --- a/internal/routes/routes.go +++ b/internal/routes/routes.go @@ -25,6 +25,9 @@ func SetupRoutes(a *app.App) http.Handler { sub, _ := fs.Sub(assets.AssetsFS, ".") mux.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(sub)))) + // Home + mux.HandleFunc("GET /{$}", home.HomePage) + // Auth pages authRateLimiter := middleware.RateLimitAuth()