Files
hnh-map/internal/app/router.go
Nikolay Tatarinov 6529d7370e Add configuration files and update project documentation
- Introduced .editorconfig for consistent coding styles across the project.
- Added .golangci.yml for Go linting configuration.
- Updated AGENTS.md to clarify project structure and components.
- Enhanced CONTRIBUTING.md with Makefile usage for common tasks.
- Updated Dockerfiles to use Go 1.24 and improved build instructions.
- Refined README.md and deployment documentation for clarity.
- Added testing documentation in testing.md for backend and frontend tests.
- Introduced Makefile for streamlined development commands and tasks.
2026-03-01 01:51:47 +03:00

36 lines
1.0 KiB
Go

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
}