add simple / path handler
This commit is contained in:
parent
86e7db59ee
commit
7a264bf0bc
2 changed files with 18 additions and 1 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
|
||||||
|
)
|
||||||
|
|
||||||
type homeHandler struct{}
|
type homeHandler struct{}
|
||||||
|
|
||||||
|
|
@ -8,6 +12,16 @@ func NewHomeHandler() *homeHandler {
|
||||||
return &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) {
|
func (home *homeHandler) NotFoundPage(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
w.Write([]byte("404 Page Not Found"))
|
w.Write([]byte("404 Page Not Found"))
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ func SetupRoutes(a *app.App) http.Handler {
|
||||||
sub, _ := fs.Sub(assets.AssetsFS, ".")
|
sub, _ := fs.Sub(assets.AssetsFS, ".")
|
||||||
mux.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(sub))))
|
mux.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(sub))))
|
||||||
|
|
||||||
|
// Home
|
||||||
|
mux.HandleFunc("GET /{$}", home.HomePage)
|
||||||
|
|
||||||
// Auth pages
|
// Auth pages
|
||||||
authRateLimiter := middleware.RateLimitAuth()
|
authRateLimiter := middleware.RateLimitAuth()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue