feat: add supervisor prototype with embedded frontend
This commit is contained in:
42
internal/httpserver/router.go
Normal file
42
internal/httpserver/router.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user