36 lines
865 B
Go
36 lines
865 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
)
|
|
|
|
func NewRouter(h *Handler) http.Handler {
|
|
r := chi.NewRouter()
|
|
r.Use(middleware.Logger)
|
|
r.Use(middleware.Recoverer)
|
|
r.Use(middleware.RealIP)
|
|
|
|
r.Route("/api/v1", func(r chi.Router) {
|
|
r.Post("/auth/login", h.Login)
|
|
|
|
r.Group(func(r chi.Router) {
|
|
r.Use(requireJWT)
|
|
r.Post("/auth/change-password", h.ChangePassword)
|
|
r.Get("/agents", h.ListAgents)
|
|
r.Post("/agents/token", h.CreateAgentToken)
|
|
r.Patch("/agents/{agentID}", h.UpdateAgent)
|
|
r.Get("/containers", h.ListContainers)
|
|
r.Post("/agents/{agentID}/containers/{containerID}/action", h.ContainerAction)
|
|
r.Get("/agents/{agentID}/containers/{containerID}/logs", h.LogsWS)
|
|
r.Get("/events", h.EventsWS)
|
|
})
|
|
})
|
|
|
|
r.Handle("/*", http.FileServer(http.Dir("./web/dist")))
|
|
|
|
return r
|
|
}
|