Functions
New
Creates frontend middleware with default options.root(string): Directory containing built frontend files
mizu.Middleware
Example:
Dev
Creates development-only middleware that proxies to dev server.devServerURL(string): URL of frontend dev server
mizu.Middleware
Example:
WithFS
Creates production middleware with embedded filesystem.fsys(fs.FS): Embedded filesystem containing frontend files
mizu.Middleware
Example:
WithOptions
Creates middleware with full configuration.opts(Options): Configuration options
mizu.Middleware
Example:
Types
Options
Configuration for the frontend middleware.- Type:
Mode - Default:
ModeAuto - Description: Controls how middleware operates
- Type:
string - Default:
"dist" - Description: Directory containing built frontend files
- Type:
fs.FS - Default:
nil - Description: Embedded filesystem (takes precedence over Root)
- Type:
string - Default:
"index.html" - Description: Fallback file for SPA routing
- Type:
string - Default:
"" - Description: URL prefix for serving frontend
- Type:
[]string - Default:
[]string{"/api", "/health", "/metrics"} - Description: Paths that bypass frontend middleware
- Type:
CacheConfig - Default: See CacheConfig defaults
- Description: Caching behavior configuration
- Type:
string - Default:
"http://localhost:5173" - Description: URL of frontend dev server
- Type:
time.Duration - Default:
30 * time.Second - Description: Timeout for dev server requests
- Type:
bool - Default:
true - Description: Enable WebSocket proxying for HMR
- Type:
string - Default:
"" - Description: Path to build manifest file
- Type:
[]string - Default:
nil - Description: Environment variables to inject into HTML
- Type:
map[string]string - Default:
nil - Description: Meta tags to inject into HTML
- Type:
bool - Default:
true - Description: Enable default security headers
- Type:
bool - Default:
false - Description: Allow serving source map files
- Type:
string - Default:
"" - Description: Path to service worker file
- Type:
func(*mizu.Ctx, error) error - Default:
nil - Description: Custom error handler
- Type:
func(*mizu.Ctx) error - Default:
nil - Description: Handler called before SPA fallback
Mode
Operating mode for the middleware.ModeDev: Always proxy to dev serverModeProduction: Always serve static filesModeAuto: Auto-detect based on environment
CacheConfig
Caching behavior configuration.- Type:
time.Duration - Default:
365 * 24 * time.Hour(1 year) - Description: Cache duration for files with content hash
- Type:
time.Duration - Default:
7 * 24 * time.Hour(1 week) - Description: Cache duration for files without hash
- Type:
time.Duration - Default:
0(no-cache) - Description: Cache duration for HTML files
- Type:
map[string]time.Duration - Default:
nil - Description: Custom cache durations for file patterns
Manifest API
LoadManifest
Loads a build manifest from filesystem.fsys(fs.FS): Filesystem containing manifestpath(string): Path to manifest file
*Manifest: Loaded manifesterror: Error if loading fails
Manifest Methods
Injection Functions
InjectEnv
Injects environment variables into HTML.html([]byte): HTML contentvars([]string): Environment variable names to inject
InjectMeta
Injects meta tags into HTML.html([]byte): HTML contentmeta(map[string]string): Meta tags (name → content)
InjectPreload
Injects preload link tags into HTML.html([]byte): HTML contentassets([]PreloadAsset): Assets to preload