package api import ( "io/fs" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "git.georgsen.dk/hwlab/internal/api/handlers" ) // NewRouter creates the chi router. staticFiles is the fs.FS rooted at web/dist, // passed from main.go where the go:embed directive lives. func NewRouter(staticFiles fs.FS) http.Handler { r := chi.NewRouter() r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Use(middleware.RealIP) r.Route("/api", func(r chi.Router) { r.Get("/health", handlers.Health) }) // SPA fallback — serve index.html for all non-API routes fileServer := http.FileServer(http.FS(staticFiles)) r.Handle("/*", fileServer) return r }