Something went wrong. Try again.
forked from charmbracelet/soft-serve
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041package web
import ( "context" "net/http"
"charm.land/log/v2" "github.com/charmbracelet/soft-serve/pkg/config" "github.com/gorilla/handlers" "github.com/gorilla/mux")
// NewRouter returns a new HTTP router.func NewRouter(ctx context.Context) http.Handler { logger := log.FromContext(ctx).WithPrefix("http") router := mux.NewRouter()
// Health routes HealthController(ctx, router)
// Git routes GitController(ctx, router)
router.PathPrefix("/").HandlerFunc(renderNotFound)
// Context handler // Adds context to the request h := NewLoggingMiddleware(router, logger) h = NewContextHandler(ctx)(h) h = handlers.RecoveryHandler()(h)
cfg := config.FromContext(ctx)
h = handlers.CORS(handlers.AllowedHeaders(cfg.HTTP.CORS.AllowedHeaders), handlers.AllowedOrigins(cfg.HTTP.CORS.AllowedOrigins), handlers.AllowedMethods(cfg.HTTP.CORS.AllowedMethods), )(h)
return h}