31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package httpapi
|
|
|
|
import "net/http"
|
|
|
|
func (s *Server) Router() http.Handler {
|
|
mux := http.NewServeMux()
|
|
|
|
// открытые
|
|
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })
|
|
mux.HandleFunc("POST /api/login", s.handleLogin)
|
|
mux.HandleFunc("POST /api/logout", s.handleLogout)
|
|
|
|
// защищённые
|
|
api := http.NewServeMux()
|
|
api.HandleFunc("GET /api/endpoints", s.handleListEndpoints)
|
|
api.HandleFunc("POST /api/endpoints", s.handleCreateEndpoint)
|
|
api.HandleFunc("GET /api/tasks", s.handleListTasks)
|
|
api.HandleFunc("POST /api/tasks", s.handleCreateTask)
|
|
api.HandleFunc("GET /api/tasks/{id}", s.handleGetTask)
|
|
api.HandleFunc("POST /api/tasks/{id}/accounts", s.handleCreateAccount)
|
|
api.HandleFunc("POST /api/tasks/{id}/import", s.handleImportCSV)
|
|
api.HandleFunc("POST /api/tasks/{id}/test", s.handleTestAccounts)
|
|
api.HandleFunc("POST /api/tasks/{id}/run", s.handleRun)
|
|
mux.Handle("/api/", s.requireAuth(api))
|
|
mux.Handle("/ws", s.requireAuth(http.HandlerFunc(s.handleWS)))
|
|
|
|
// SPA static (fallback)
|
|
mux.Handle("/", s.staticHandler())
|
|
return mux
|
|
}
|