From 60eafdc6e2382d85c97b27bd7143416a2902d33b Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Sun, 14 Dec 2025 08:56:25 -0300 Subject: [PATCH] feat(backend): add root route with IP info and move swagger to /docs - Add root route (/) returning JSON with client IP, API info and links - Move Swagger docs from /swagger/ to /docs/ - Include X-Forwarded-For and X-Real-IP header support for proxy environments --- backend/internal/router/router.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/backend/internal/router/router.go b/backend/internal/router/router.go index f055d05..6d69abb 100755 --- a/backend/internal/router/router.go +++ b/backend/internal/router/router.go @@ -62,6 +62,33 @@ func NewRouter() http.Handler { jobHandler := handlers.NewJobHandler(jobService) applicationHandler := handlers.NewApplicationHandler(applicationService) + // --- ROOT ROUTE --- + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + // Get client IP + clientIP := r.Header.Get("X-Forwarded-For") + if clientIP == "" { + clientIP = r.Header.Get("X-Real-IP") + } + if clientIP == "" { + clientIP = r.RemoteAddr + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + response := `{ + "message": "🐴 GoHorseJobs API is running!", + "ip": "` + clientIP + `", + "docs": "/docs", + "health": "/health", + "version": "1.0.0" +}` + w.Write([]byte(response)) + }) + mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("OK")) @@ -106,8 +133,8 @@ func NewRouter() http.Handler { log.Println("S3 storage routes registered successfully") } - // Swagger Route - mux.HandleFunc("/swagger/", httpSwagger.WrapHandler) + // Swagger Route - available at /docs + mux.HandleFunc("/docs/", httpSwagger.WrapHandler) // Apply middleware chain: Security Headers -> Rate Limiting -> CORS -> Router // Order matters: outer middleware runs first