feat: add http utilities to middleware package
This commit is contained in:
parent
e747906f18
commit
669c01716c
1 changed files with 23 additions and 0 deletions
23
internal/middleware/utils.go
Normal file
23
internal/middleware/utils.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui/pages"
|
||||
)
|
||||
|
||||
func redirect(w http.ResponseWriter, r *http.Request, path string, code int) {
|
||||
// For HTMX requests, use HX-Redirect header to force full page redirect
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
w.Header().Set("HX-Redirect", "/auth")
|
||||
w.WriteHeader(code)
|
||||
return
|
||||
}
|
||||
// For regular requests, use standard redirect
|
||||
http.Redirect(w, r, "/auth", code)
|
||||
}
|
||||
|
||||
func notfound(w http.ResponseWriter, r *http.Request) {
|
||||
ui.Render(w, r, pages.NotFound())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue