frontend

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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`.

func Setup

func Setup(router *mux.Router, frontend embed.FS, distPath string)

Setup configures frontend serving on the given router. In development mode (detected via IsDev()), it proxies requests to the Vite dev server. In production mode, it serves static files from the embedded filesystem.

func SetupWithConfig

func SetupWithConfig(router *mux.Router, frontend embed.FS, cfg *Config)

SetupWithConfig configures frontend serving with custom configuration.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL