package app import ( "net/http" "github.com/go-chi/chi/v5" ) // APIHandler is the interface for API routing (implemented by handlers.Handlers). type APIHandler interface { APIRouter(rw http.ResponseWriter, req *http.Request) ClientRouter(rw http.ResponseWriter, req *http.Request) RedirectLogout(rw http.ResponseWriter, req *http.Request) WatchGridUpdates(rw http.ResponseWriter, req *http.Request) GridTile(rw http.ResponseWriter, req *http.Request) } // Router returns the HTTP router for the app. func (a *App) Router(publicDir string, h APIHandler) http.Handler { r := chi.NewRouter() r.Handle("/js/*", http.FileServer(http.Dir(publicDir))) r.HandleFunc("/client/*", h.ClientRouter) r.HandleFunc("/logout", h.RedirectLogout) r.Route("/map", func(r chi.Router) { r.HandleFunc("/api/*", h.APIRouter) r.HandleFunc("/updates", h.WatchGridUpdates) r.Handle("/grids/*", http.StripPrefix("/map/grids", http.HandlerFunc(h.GridTile))) }) r.HandleFunc("/*", a.ServeSPARoot) return r }