feat: add custom 404 not found handler

This commit is contained in:
Siesta
2025-07-28 21:09:06 +02:00
parent f0bc335f0d
commit 59db9d263f
+6
View File
@@ -8,12 +8,14 @@ import (
"github.com/siestaw/laterna/server/cmd/internal/db" "github.com/siestaw/laterna/server/cmd/internal/db"
"github.com/siestaw/laterna/server/cmd/internal/logger" "github.com/siestaw/laterna/server/cmd/internal/logger"
"github.com/siestaw/laterna/server/cmd/internal/routes" "github.com/siestaw/laterna/server/cmd/internal/routes"
"github.com/siestaw/laterna/server/cmd/utils"
) )
func StartHTTPServer() { func StartHTTPServer() {
router := http.NewServeMux() router := http.NewServeMux()
routes.RegisterColorRoutes(router) routes.RegisterColorRoutes(router)
routes.RegisterControllerRoutes(router) routes.RegisterControllerRoutes(router)
router.HandleFunc("/", notFoundHandler)
if !db.ControllerExists(0) { if !db.ControllerExists(0) {
adminToken := db.CreateAdmin() adminToken := db.CreateAdmin()
@@ -29,3 +31,7 @@ func StartHTTPServer() {
logger.HTTPLogger.Printf("HTTP Server running on :%v", port) logger.HTTPLogger.Printf("HTTP Server running on :%v", port)
http.ListenAndServe(fmt.Sprintf(":%d", port), router) http.ListenAndServe(fmt.Sprintf(":%d", port), router)
} }
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
utils.ErrorResponse(w, http.StatusNotFound, "Not found")
}