Documentation
¶
Overview ¶
Package frontend provides SPA serving utilities for Go web applications. It supports both development mode (proxying to Vite dev server) and production mode (serving embedded static files).
Index ¶
Constants ¶
const (
// DefaultDevHost is the default Vite dev server address.
DefaultDevHost = "localhost:5173"
)
Variables ¶
This section is empty.
Functions ¶
func IsDev ¶
func IsDev() bool
IsDev returns true when the application is running via `go run`. It detects this by checking if the executable path contains "go-build", which is the temporary directory used by `go run`.
Types ¶
type Config ¶
type Config struct {
// DevHost is the address of the Vite dev server (default: localhost:5173).
DevHost string
// DistPath is the path to the embedded dist directory (e.g., "frontend/dist").
DistPath string
// IndexFile is the name of the index file (default: "index.html").
IndexFile string
}
Config holds the configuration for frontend serving.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default frontend configuration.
type SPAHandler ¶
type SPAHandler struct {
// contains filtered or unexported fields
}
SPAHandler serves a Single Page Application from an embedded filesystem. It serves static files when they exist and falls back to index.html for client-side routing.
func NewSPAHandler ¶
func NewSPAHandler(frontend embed.FS, distPath, indexFile string) *SPAHandler
NewSPAHandler creates a new SPA handler.
func (*SPAHandler) ServeHTTP ¶
func (h *SPAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for serving the SPA.