30 lines
773 B
Go
30 lines
773 B
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// TODO CLEANUP: Test route for now
|
|
func (s *Server) handleHome() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
// 1. Grab the userID from the context (placed there by s.hasAuth)
|
|
userID, ok := userIDFromContext(r.Context())
|
|
if !ok {
|
|
// Technically never happen if the middleware is working...
|
|
log.Printf("UNAUTHORIZED!")
|
|
http.Error(w, "User not found in context", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
// 2. Respond with something that proves it works
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"message": "Welcome to the nfeeder API!",
|
|
"user_id": userID,
|
|
"status": "authenticated",
|
|
})
|
|
}
|
|
}
|