Add JSON validation middleware to ensure valid API responses
- Created JSONValidationMiddleware that validates all JSON responses - Ensures that even on timeout or internal errors, a valid JSON error response is returned - Applied to all API endpoints including /status.json - Prevents client-side JSON parse errors when server encounters issues
This commit is contained in:
@@ -23,7 +23,7 @@ func (s *Server) setupRoutes() {
|
||||
// Routes
|
||||
r.Get("/", s.handleRoot())
|
||||
r.Get("/status", s.handleStatusHTML())
|
||||
r.Get("/status.json", s.handleStatusJSON())
|
||||
r.Get("/status.json", JSONValidationMiddleware(s.handleStatusJSON()).ServeHTTP)
|
||||
|
||||
// AS and prefix detail pages
|
||||
r.Get("/as/{asn}", s.handleASDetail())
|
||||
@@ -33,6 +33,7 @@ func (s *Server) setupRoutes() {
|
||||
|
||||
// API routes
|
||||
r.Route("/api/v1", func(r chi.Router) {
|
||||
r.Use(JSONValidationMiddleware)
|
||||
r.Get("/stats", s.handleStats())
|
||||
r.Get("/ip/{ip}", s.handleIPLookup())
|
||||
r.Get("/as/{asn}", s.handleASDetailJSON())
|
||||
|
||||
Reference in New Issue
Block a user