mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
feat: add custom 404 not found handler
This commit is contained in:
@@ -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")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user