Merge remote-tracking branch 'origin/main' into LPM-48

This commit is contained in:
Robin Olsen
2026-03-06 13:03:53 +01:00
44 changed files with 2163 additions and 205 deletions

View File

@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/pkg/web/handler"
"github.com/NYTimes/gziphandler"
"github.com/go-chi/chi/v5"
@@ -19,13 +20,16 @@ import (
func (s *Server) RegisterRoutes(assets embed.FS) http.Handler {
r := chi.NewRouter()
r.Use(middleware.Logger)
if os.Getenv("DEV") == "True" {
r.Use(middleware.Logger)
}
r.Use(middleware.Recoverer)
r.Use(cors.AllowAll().Handler)
r.Use(middleware.CleanPath)
r.Use(handler.HTMXMiddleware)
r.Use(handler.AppMiddleware(s.App))
r.Use(actionLoggingMiddleware(s.App))
s.handleAssets(r, assets)
@@ -57,6 +61,35 @@ func (s *Server) RegisterRoutes(assets embed.FS) http.Handler {
return gziphandler.GzipHandler(r)
}
func actionLoggingMiddleware(app interface{ LogAction(string) }) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if app != nil && shouldLogWebAction(r.URL.Path) {
app.LogAction(models.EncodeActionEvent(models.ActionEvent{
Source: "web",
Action: "request",
Target: r.Method + " " + r.URL.Path,
Result: "ok",
}))
}
next.ServeHTTP(w, r)
})
}
}
func shouldLogWebAction(path string) bool {
if strings.HasPrefix(path, "/assets/") {
return false
}
switch path {
case "/status":
return false
default:
return true
}
}
func (s *Server) handleAssets(r chi.Router, assets embed.FS) {
var fileServer http.Handler