package server import ( "time" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) const ( requestTimeout = 60 * time.Second // maxRequestBodyBytes caps every request body. A route group // can mount s.mw.MaxBodyBytes with a smaller value to lower // its bound, but cannot raise it: this cap runs first. maxRequestBodyBytes int64 = 1 << 20 // 1 MiB ) // SetupRoutes configures the chi router with middleware and // all application routes. func (s *Server) SetupRoutes() { s.router = chi.NewRouter() s.router.Use(s.mw.Recoverer()) s.router.Use(middleware.RequestID) s.router.Use(s.mw.Logging()) s.router.Use(s.mw.SecurityHeaders()) s.router.Use(s.mw.CORS()) s.router.Use(s.mw.MaxBodyBytes(maxRequestBodyBytes)) s.router.Use(middleware.Timeout(requestTimeout)) s.router.Get( "/.well-known/healthcheck", s.h.HandleHealthCheck(), ) s.router.Route("/api/v1", func(r chi.Router) { r.Post("/reports", s.h.HandleReport()) }) }