feat: add supervisor prototype with embedded frontend

This commit is contained in:
root
2026-03-09 19:15:53 +01:00
parent 96c4ce1697
commit 84de557052
56 changed files with 4044 additions and 10 deletions

View File

@ -0,0 +1,42 @@
package httpserver
import (
"log"
"net/http"
"supervisor/internal/httpserver/handlers"
"supervisor/internal/static"
)
type Dependencies struct {
Logger *log.Logger
Manager handlers.SessionService
}
func NewRouter(deps Dependencies) (http.Handler, error) {
mux := http.NewServeMux()
healthHandler := handlers.HealthHandler{}
sessions := handlers.NewSessionsHandler(deps.Manager)
wsHandler := handlers.NewWSTerminalHandler(deps.Manager)
mux.HandleFunc("GET /healthz", healthHandler.Handle)
mux.HandleFunc("GET /api/sessions", sessions.List)
mux.HandleFunc("POST /api/sessions", sessions.Create)
mux.HandleFunc("GET /api/sessions/{id}", sessions.Get)
mux.HandleFunc("POST /api/sessions/{id}/input", sessions.Input)
mux.HandleFunc("POST /api/sessions/{id}/stop", sessions.Stop)
mux.HandleFunc("DELETE /api/sessions/{id}", sessions.Delete)
mux.HandleFunc("GET /ws/sessions/{id}", wsHandler.Handle)
staticHandler, err := static.NewSPAHandler()
if err != nil {
return nil, err
}
mux.Handle("/", staticHandler)
var root http.Handler = mux
root = RecoverMiddleware(deps.Logger, root)
root = LoggingMiddleware(deps.Logger, root)
return root, nil
}