Additional security and hardening.

This commit is contained in:
2025-03-31 15:14:16 +01:00
parent c3a7480c65
commit 7eefb9ced0
13 changed files with 274 additions and 47 deletions

20
middleware/recover.go Normal file
View File

@@ -0,0 +1,20 @@
package middleware
import (
"log"
"net/http"
"runtime/debug"
)
func Recover(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if rec := recover(); rec != nil {
log.Printf("🔥 Recovered from panic: %v\n%s", rec, debug.Stack())
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
})
}