1package web
 2
 3import (
 4	"context"
 5	"net/http"
 6
 7	"github.com/charmbracelet/log/v2"
 8	"github.com/gorilla/handlers"
 9	"github.com/gorilla/mux"
10)
11
12// NewRouter returns a new HTTP router.
13func NewRouter(ctx context.Context) http.Handler {
14	logger := log.FromContext(ctx).WithPrefix("http")
15	router := mux.NewRouter()
16
17	// Health routes
18	HealthController(ctx, router)
19
20	// Git routes
21	GitController(ctx, router)
22
23	// Web UI routes (must be after Git routes)
24	WebUIController(ctx, router)
25
26	// Catch-all route (must be last)
27	router.PathPrefix("/").HandlerFunc(renderNotFound)
28
29	// Context handler
30	// Adds context to the request
31	h := NewLoggingMiddleware(router, logger)
32	h = NewContextHandler(ctx)(h)
33	h = handlers.CompressHandler(h)
34	h = handlers.RecoveryHandler()(h)
35
36	return h
37}