212875ed0d
- .claude/agents/fn-orquestador/SKILL.md - .claude/commands/fn_claude.md - .claude/rules/INDEX.md - .claude/rules/cpp_apps.md - .claude/rules/ids_naming.md - CHANGELOG.md - apps/dag_engine/README.md - apps/dag_engine/api.go - apps/dag_engine/dags_migrated/example.yaml - apps/dag_engine/dags_migrated/example_lineage_tracking.yaml - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
)
|
|
|
|
// RegisterAPI sets up all HTTP routes on the given mux.
|
|
func RegisterAPI(mux *http.ServeMux, executor *Executor, scheduler *Scheduler, hub *DagRunHub, frontendFS fs.FS) {
|
|
// API routes.
|
|
mux.HandleFunc("GET /api/dags", handleListDags(executor))
|
|
mux.HandleFunc("GET /api/dags/{name}", handleGetDag(executor))
|
|
mux.HandleFunc("POST /api/dags/{name}/run", handleRunDag(executor))
|
|
|
|
mux.HandleFunc("GET /api/runs", handleListRuns(executor))
|
|
mux.HandleFunc("GET /api/runs/{id}", handleGetRun(executor))
|
|
|
|
// Function lookup proxy a registry.db (read-only).
|
|
mux.HandleFunc("GET /api/functions/{id}", handleGetFunction())
|
|
|
|
mux.HandleFunc("POST /api/scheduler/start", handleSchedulerStart(scheduler))
|
|
mux.HandleFunc("POST /api/scheduler/stop", handleSchedulerStop(scheduler))
|
|
mux.HandleFunc("GET /api/scheduler/status", handleSchedulerStatus(scheduler))
|
|
|
|
// Live updates (WS hub).
|
|
if hub != nil {
|
|
mux.HandleFunc("GET /api/ws/dagruns", handleDagRunsWS(hub))
|
|
}
|
|
|
|
// Frontend SPA fallback.
|
|
if frontendFS != nil {
|
|
mux.Handle("/", spaHandler(frontendFS))
|
|
}
|
|
}
|
|
|
|
// spaHandler serves static files from the embedded FS, falling back to index.html
|
|
// for unknown paths (SPA client-side routing).
|
|
func spaHandler(fsys fs.FS) http.Handler {
|
|
fileServer := http.FileServer(http.FS(fsys))
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Try to serve the file directly.
|
|
path := r.URL.Path
|
|
if path == "/" {
|
|
path = "index.html"
|
|
} else {
|
|
path = path[1:] // strip leading /
|
|
}
|
|
|
|
if _, err := fs.Stat(fsys, path); err != nil {
|
|
// File not found — serve index.html for SPA routing.
|
|
r.URL.Path = "/"
|
|
}
|
|
fileServer.ServeHTTP(w, r)
|
|
})
|
|
}
|