package web import ( _ "embed" "encoding/json" "net/http" cadatlas "git.d-ma.be/mathias/cad-atlas" "git.d-ma.be/mathias/cad-atlas/internal/atlas" ) // atlasHTML is the Phase-A/B static shell. It fetches /api/atlas.json at load // and renders from that data (no inline arrays), so the content is sourced. // //go:embed static/cad-atlas.html var atlasHTML []byte // NewHandler serves the CAD Atlas: the shell at "/", and the sourced data at // "/api/atlas.json" (authored data + CI stage generated from the real cd.yml). func NewHandler() http.Handler { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write(atlasHTML) }) mux.HandleFunc("/api/atlas.json", func(w http.ResponseWriter, r *http.Request) { a, err := atlas.Default(cadatlas.CDWorkflow) if err != nil { http.Error(w, "atlas build failed", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") _ = json.NewEncoder(w).Encode(a) }) return mux }