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 router.PathPrefix("/").HandlerFunc(renderNotFound)
24
25 // Context handler
26 // Adds context to the request
27 h := NewLoggingMiddleware(router, logger)
28 h = NewContextHandler(ctx)(h)
29 h = handlers.CompressHandler(h)
30 h = handlers.RecoveryHandler()(h)
31
32 return h
33}