diff --git a/.gitignore b/.gitignore index ff6fc96..4d4680f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ # prettier cache (npm run format in web/ walks up here) /node_modules/ + +# real frontend builds copied over the committed placeholder (index.html +# stays tracked; `git restore internal/webdist/dist` after local testing) +/internal/webdist/dist/* +!/internal/webdist/dist/index.html diff --git a/cmd/spreadlab/main.go b/cmd/spreadlab/main.go index 13429cd..11890f5 100644 --- a/cmd/spreadlab/main.go +++ b/cmd/spreadlab/main.go @@ -1,6 +1,7 @@ -// Command spreadlab serves the spreadlab API (and, from milestone 4, the -// dashboard itself). The -table flag instead prints the three-scenario -// comparison and exits, a quick engine sanity check. +// Command spreadlab serves the dashboard and its API from one binary: +// the embedded frontend on /, the API under /api, and a trivial +// /healthz for container healthchecks. The -table flag instead prints +// the three-scenario comparison and exits, a quick engine sanity check. package main import ( @@ -14,6 +15,7 @@ import ( "github.com/JustinZeus/spreadlab/internal/api" "github.com/JustinZeus/spreadlab/internal/engine" + "github.com/JustinZeus/spreadlab/internal/webdist" ) func main() { @@ -29,8 +31,17 @@ func main() { return } - log.Printf("spreadlab API listening on http://%s", *addr) - if err := http.ListenAndServe(*addr, api.NewServer()); err != nil { + // One mux, one origin: the longer /api/ pattern wins over / for API + // calls, everything else falls through to the embedded frontend. + mux := http.NewServeMux() + mux.Handle("/api/", api.NewServer()) + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusNoContent) + }) + mux.Handle("/", webdist.Handler()) + + log.Printf("spreadlab listening on http://%s", *addr) + if err := http.ListenAndServe(*addr, mux); err != nil { log.Fatal(err) } } diff --git a/internal/webdist/dist/index.html b/internal/webdist/dist/index.html new file mode 100644 index 0000000..c3e14da --- /dev/null +++ b/internal/webdist/dist/index.html @@ -0,0 +1,4 @@ + + +
Placeholder page: this binary was built without the frontend. Run npm run build in web/ and copy web/dist over internal/webdist/dist, or use the Docker image.