Serve frontend SPA from Go binary #17

Open
opened 2026-03-16 22:32:19 +00:00 by austin · 0 comments
Owner

The Dockerfile builds the frontend into web/dist but the Go binary never serves it. In production, everything should be served from the single binary.

What needs to happen

Production serving:
Use go:embed to embed the web/dist directory into the binary. Serve it on all routes that don't match /api/ or /auth/. Add a fallback: any non-file request returns index.html (SPA client-side routing).

Development proxy:
Add a Vite proxy config in vite.config.ts so /api and /auth requests forward to localhost:8659 during development. This lets you run vite dev and the Go server separately.

Key files

  • cmd/vektor/main.go or internal/api/server.go — embed and serve static files
  • web/vite.config.ts — add dev proxy
The Dockerfile builds the frontend into `web/dist` but the Go binary never serves it. In production, everything should be served from the single binary. ## What needs to happen **Production serving:** Use `go:embed` to embed the `web/dist` directory into the binary. Serve it on all routes that don't match `/api/` or `/auth/`. Add a fallback: any non-file request returns `index.html` (SPA client-side routing). **Development proxy:** Add a Vite proxy config in `vite.config.ts` so `/api` and `/auth` requests forward to `localhost:8659` during development. This lets you run `vite dev` and the Go server separately. ## Key files - `cmd/vektor/main.go` or `internal/api/server.go` — embed and serve static files - `web/vite.config.ts` — add dev proxy
austin self-assigned this 2026-03-16 22:32:19 +00:00
austin added this to the Vektor - CLI project 2026-03-16 22:32:19 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
austin/vektor#17
No description provided.