feat: add HTTP handlers and health endpoint
Implement all HTTP handlers using Go 1.22+ stdlib ServeMux with
HTMX fragment vs full-page response detection.
- internal/handlers/handlers.go: all route handlers
- GET /health returns 200 for K8s probes
- GET / dashboard with triage queue from aggregation layer
- GET /issues lists all issues across orgs
- GET /pulls lists all PRs across orgs
- POST /issues creates issue via aggregation layer
- POST /issues/{owner}/{repo}/{index}/labels assigns labels
- POST /pulls/{owner}/{repo}/{index}/review submits PR review
- HX-Request header detection for HTMX fragment vs full page
- Mobile-first dark theme base layout with bottom navigation
- cmd/server/main.go: refactored to use centralized route registration
- internal/handlers/handlers_test.go: unit tests for health, dashboard,
HTMX detection, input validation
Closes leeworks-agents/gitea-mobile#4
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+6
-27
@@ -1,14 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/config"
|
||||
giteaclient "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/gitea"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/handlers"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware"
|
||||
)
|
||||
@@ -24,33 +23,13 @@ func main() {
|
||||
log.Fatalf("configuration error: %v", err)
|
||||
}
|
||||
|
||||
// Determine if cookies should be marked Secure (disable for local dev).
|
||||
secureCookies := !strings.HasPrefix(cfg.ListenAddr, "localhost") &&
|
||||
!strings.HasPrefix(cfg.ListenAddr, "127.0.0.1")
|
||||
// Create Gitea API client.
|
||||
client := giteaclient.NewClient(cfg.GiteaURL)
|
||||
|
||||
// Create handler with all routes.
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Health endpoint (no auth required).
|
||||
mux.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintln(w, "ok")
|
||||
})
|
||||
|
||||
// Settings handler.
|
||||
settingsHandler := &handlers.SettingsHandler{
|
||||
SessionSecret: cfg.SessionSecret,
|
||||
SecureCookies: secureCookies,
|
||||
}
|
||||
mux.HandleFunc("/settings", settingsHandler.ServeHTTP)
|
||||
|
||||
// Static file server.
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
||||
// Placeholder dashboard (will be replaced in issue #4/#5).
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprintln(w, "<h1>Gitea Mobile</h1><p>Dashboard coming soon.</p>")
|
||||
})
|
||||
h := handlers.NewHandler(cfg, client)
|
||||
h.RegisterRoutes(mux)
|
||||
|
||||
// Apply middleware chain: logging -> auth.
|
||||
var handler http.Handler = mux
|
||||
|
||||
Reference in New Issue
Block a user