Skip to main content
The frontend middleware offers extensive configuration options to handle various deployment scenarios, frameworks, and requirements.

Basic Configuration

Minimal Setup

The simplest configuration:
This uses sensible defaults:
  • Auto-detects mode based on MIZU_ENV
  • Serves from ./dist in production
  • Proxies to http://localhost:5173 in development
  • Ignores /api, /health, /metrics

With Dev Server

Specify both production and development:

Embedded Filesystem

Use embedded files for single-binary deployment:

Options Reference

Mode

Controls how the middleware operates.
Usage:
Auto-detection logic: Environment variable checked in order:
  1. MIZU_ENV
  2. GO_ENV
  3. ENV
If value is "production" or "prod" (case-insensitive) → Production mode Otherwise → Development mode

Root

Directory containing built frontend files (production only).
Path resolution:
  • Relative paths are relative to working directory
  • Absolute paths work as expected
Common paths:
  • Vite: "./dist"
  • Angular: "./dist/my-app/browser"
  • Next.js: "./out"
  • Nuxt: "./dist"

FS (Embedded Filesystem)

Embedded filesystem for production builds (takes precedence over Root).
Why use fs.Sub? The embed directive includes the directory name:
Using fs.Sub extracts the subdirectory:
Now index.html is at the root level as expected.

Index

The fallback HTML file for SPA routing.
When is it used?
  • Request path is / or empty
  • Requested file doesn’t exist (SPA fallback)
  • Requested path is a directory

DevServer

URL of the frontend development server.
Common dev server URLs:
  • Vite: "http://localhost:5173"
  • Angular: "http://localhost:4200"
  • Next.js: "http://localhost:3000"
  • Create React App: "http://localhost:3000"

DevServerTimeout

Timeout for requests to the dev server.
Increase for slow dev servers:

ProxyWebSocket

Enable WebSocket proxying for HMR.
Disable if you don’t need HMR:

Prefix

URL prefix for serving the frontend.
Routing:
  • /app → index.html
  • /app/about → index.html (SPA fallback)
  • /app/assets/main.js → assets/main.js
  • / → Not handled by frontend middleware
Frontend router configuration required:

IgnorePaths

Paths that bypass the frontend middleware and go to Go handlers.
Add custom paths:
Disable all:

CacheControl

Configure caching behavior for different asset types.
CacheConfig fields:
  • HashedAssets: Files with content hash in name (e.g., main.abc123.js)
  • UnhashedAssets: Files without hash (e.g., logo.png)
  • HTML: HTML files (.html)
  • Patterns: Custom patterns override defaults
See Caching Strategy for details.

SecurityHeaders

Enable automatic security headers.
Headers added:
Disable if using helmet:

SourceMaps

Allow serving source map files (.js.map, .css.map).
Enable for debugging:
Conditional source maps:

Manifest

Path to build manifest for asset mapping.
The manifest is used for:
  • Asset fingerprinting
  • Module preloading
  • CSS injection
  • Template helpers
See Build Manifest for details.

InjectEnv

Inject server-side environment variables into the frontend.
Variables are exposed as window.__ENV__:
Security warning: Only inject non-sensitive values. These are visible to users. See Environment Injection for details.

InjectMeta

Inject custom meta tags into HTML.
Injects:

ServiceWorker

Path to service worker file for PWA support.
Proper headers are added for service worker scope. See Service Workers for details.

ErrorHandler

Custom error handler for frontend errors.

NotFoundHandler

Custom handler called before SPA fallback.

Configuration Examples

Complete Production Setup

Development-Optimized Setup

Auto-Switching Setup

Multi-Environment Setup

Environment Variables

Configure via environment:
Access in configuration:

Next Steps

Development Mode

Learn about dev mode and HMR

Production Mode

Optimize for production deployment

Caching Strategy

Deep dive into caching

Security

Security best practices