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
This commit is contained in:
parent
4475bc6bda
commit
60eafdc6e2
1 changed files with 29 additions and 2 deletions
|
|
@ -62,6 +62,33 @@ func NewRouter() http.Handler {
|
||||||
jobHandler := handlers.NewJobHandler(jobService)
|
jobHandler := handlers.NewJobHandler(jobService)
|
||||||
applicationHandler := handlers.NewApplicationHandler(applicationService)
|
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) {
|
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte("OK"))
|
w.Write([]byte("OK"))
|
||||||
|
|
@ -106,8 +133,8 @@ func NewRouter() http.Handler {
|
||||||
log.Println("S3 storage routes registered successfully")
|
log.Println("S3 storage routes registered successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swagger Route
|
// Swagger Route - available at /docs
|
||||||
mux.HandleFunc("/swagger/", httpSwagger.WrapHandler)
|
mux.HandleFunc("/docs/", httpSwagger.WrapHandler)
|
||||||
|
|
||||||
// Apply middleware chain: Security Headers -> Rate Limiting -> CORS -> Router
|
// Apply middleware chain: Security Headers -> Rate Limiting -> CORS -> Router
|
||||||
// Order matters: outer middleware runs first
|
// Order matters: outer middleware runs first
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue