config

Configuration Options

Environment exposure

EnvExposureMode

Select how variables are emitted into env.js:

  • EnvModeGlobals (default): each variable as a separate global assignment: window.NAME = "value".
  • EnvModeObject: a single object containing all variables: window.__ENV__ = { NAME: "value" }.
  • EnvModeBoth: emit both the object and the separate assignments.

Configure via WithEnvExposure(mode).

WithEnvObjectName(name string)

Sets the object name used by object modes. Default is __ENV__, producing window.__ENV__ = { ... }.

WithEnvAllowlist(keys …string)

Restrict which JSENV_ variables are exposed. Provide names without the JSENV_ prefix (e.g., WithEnvAllowlist("API_URL", "FEATURE_FLAG") for JSENV_API_URL, JSENV_FEATURE_FLAG).

Routing and behaviour

WithSPAFallback(enabled bool)

If true, unknown routes serve index.html (SPA fallback).

WithAPIPrefixes(prefixes …string)

Prefixes excluded from SPA fallback (e.g., /api).

WithMountPath(base string)

Serve files under a sub-path (e.g., /static).

Headers and caching

WithSecurityHeaders(enabled bool)

Enables recommended security headers.

WithNoCacheForIndexAndEnv()

Adds Cache-Control: no-store to index.html and env.js responses.

WithETag(enabled bool)

Adds an ETag to env.js and honours If-None-Match.

Logging

WithLogger(l Logger)

Provide a custom logger (interface: Printf(string, ...any)).