This project is a minimal Golang web server that:
go:embed (no runtime Node.js needed to run the binary)Using Makefile (recommended):
make build
This builds the Svelte SPA to cmd/shared-canvas-server/web-dist/ and then compiles the Go server. The resulting binary is embedded with the SPA assets.
Manual steps:
# 1) Build the SPA (outputs to cmd/shared-canvas-server/web-dist)
(cd webapp && npm ci && npm run build)
# 2) Build the Go server
go build ./cmd/shared-canvas-server
./shared-canvas-server -port 8080
Then open your browser at:
http://localhost:8080/
CLI options:
-port (int): Port to listen on (default: 8080)-p (int): Shorthand for -port (default: 8080)GET /api/health → { "status": "ok", "service": "shared-canvas", "time": "RFC3339Nano" }GET /api/time → { "now": "RFC3339Nano", "epoch": 173... }GET /ws (upgrades to WebSocket){ type: string, payload?: any, time?: string }{ type: "welcome", payload: { message: "connected" }, time } then echoes back any JSON you send wrapped in { type: "ack", payload: <your message>, time }.Dev usage:
go run ./cmd/shared-canvas-server -port 8080cd webapp && npm run devws://localhost:5173/ws → http://localhost:8080/ws.Production usage:
make build then run the binary (e.g., ./shared-canvas-server -p 8080)Notes:
nhooyr.io/websocket. If building manually the first time, run go mod tidy to fetch it.webapp/ (Vite + Svelte)# Terminal A: run the Go API
go run ./cmd/shared-canvas-server -port 8080
# Terminal B: run SvelteKit dev server (with API proxy)
cd webapp && npm run dev
SvelteKit dev server runs on http://localhost:5173 and proxies /api/* to http://localhost:8080.cmd/shared-canvas-server/web-dist/ and embedded into the Go binary.index.html (SPA routing).cmd/
shared-canvas-server/
main.go # server entrypoint, routes, embedding, graceful shutdown
web-dist/ # built SPA assets (embedded)
webapp/ # Svelte 5 app (Vite)
src/
App.svelte
routes/
Home.svelte
Health.svelte
Time.svelte
vite.config.ts
package.json