Phase 2/4 done, working on phase 3/5

This commit is contained in:
Martino Ferrari
2026-04-24 15:46:04 +02:00
parent 9aa89cc0cf
commit 8b548ba1c2
43 changed files with 6800 additions and 156 deletions
+14 -5
View File
@@ -6,17 +6,20 @@ import (
"log/slog"
"net/http"
"time"
"github.com/uopi/uopi/internal/api"
"github.com/uopi/uopi/internal/broker"
)
const apiPrefix = "/api/v1"
type Server struct {
httpServer *http.Server
log *slog.Logger
}
// New creates an HTTP server that serves the embedded frontend and a health
// check endpoint. Additional routes (API, WebSocket) will be registered in
// later phases.
func New(addr string, webFS fs.FS, log *slog.Logger) *Server {
// New creates the HTTP server, registers all routes, and returns a ready-to-start Server.
func New(addr string, webFS fs.FS, brk *broker.Broker, log *slog.Logger) *Server {
mux := http.NewServeMux()
// Health check
@@ -25,7 +28,13 @@ func New(addr string, webFS fs.FS, log *slog.Logger) *Server {
_, _ = w.Write([]byte("ok"))
})
// Serve embedded frontend for everything else
// WebSocket endpoint
mux.Handle("/ws", &wsHandler{broker: brk, log: log})
// REST API
api.New(brk, log).Register(mux, apiPrefix)
// Embedded frontend — must be last (catch-all)
mux.Handle("/", http.FileServerFS(webFS))
return &Server{