Skip to main content
TrailBase can be configured through command-line flags, environment variables, and configuration files. This guide covers all available configuration options.

Configuration Sources

TrailBase reads configuration from three sources in order of precedence:
  1. Environment variables (highest priority) - TRAIL_* prefix
  2. Configuration files - config.textproto and secrets.textproto
  3. Command-line flags - Passed to the trail command
  4. Defaults (lowest priority)
Environment variables always override configuration files and defaults. This is useful for Docker deployments and CI/CD pipelines.

Command-Line Options

Global Flags

These flags apply to all subcommands:

--data-dir <PATH>

Directory for runtime files including databases, configuration, and WASM components.
  • Default: ./traildepot
  • Environment variable: DATA_DIR
  • Example:
The data directory will be created automatically if it doesn’t exist. Ensure the user running TrailBase has write permissions.

--public-url <URL>

Public URL used to access TrailBase. Required for:
  • Sending authentication emails with correct links
  • OAuth2 redirect URLs
  • Generating absolute URLs in APIs
  • Default: None (optional)
  • Environment variable: PUBLIC_URL
  • Example:

--version

Print TrailBase version information and exit.

Run Command Options

Options for the trail run subcommand:

--address <HOST:PORT>

HTTP server bind address.
  • Default: localhost:4000
  • Environment variable: ADDRESS
  • Examples:
Binding to 0.0.0.0 exposes the server on all network interfaces. Use a firewall or reverse proxy to control access.

--admin-address <HOST:PORT>

Optional separate address for admin UI and APIs.
  • Default: None (admin served on main address)
  • Environment variable: ADMIN_ADDRESS
  • Example:
When set:
  • Public APIs: Served on --address
  • Admin UI & APIs: Served on --admin-address
Bind admin to localhost for security, then access via SSH tunnel in production.

--public-dir <PATH>

Optional path to static assets served at the HTTP root.
  • Default: None
  • Environment variable: PUBLIC_DIR
  • Example:
Static files are served before API routes:
  • /index.html/var/www/app/index.html
  • /assets/style.css/var/www/app/assets/style.css
  • /api/records/v1/users → TrailBase API (not a file)

--spa

Enable Single Page Application (SPA) fallback mode.
  • Default: false
  • Environment variable: SPA
  • Example:
Behavior:
  • Routes (paths without extensions) → index.html
  • File requests (e.g., .css, .js) → serve file or 404
  • API routes → TrailBase APIs
Requires --public-dir to be set. Perfect for React, Vue, Angular, or Svelte apps.

--runtime-root-fs <PATH>

Sandboxed filesystem root for WASM runtime.
  • Default: None (WASM has no filesystem access)
  • Environment variable: RUNTIME_ROOT_FS
  • Example:
Allows WASM components to access files within the specified directory.

--geoip-db-path <PATH>

Path to MaxMind GeoIP database for IP geolocation.
  • Default: None (geolocation disabled)
  • Environment variable: GEOIP_DB_PATH
  • Example:
Download GeoIP database:

--dev

Enable development mode with permissive CORS and cookies.
  • Default: false
  • Example:
Changes:
  • Allows cross-origin requests from any origin
  • Enables credentials in cross-origin requests
  • Useful for frontend dev servers
Never use --dev in production. It weakens security by allowing cross-origin requests from any domain.

--demo

Demo mode - redacts PII from logs.
  • Default: false
  • Example:
Useful for public demos or screenshots where user data should be hidden.

--stderr-logging

Log to stderr instead of the database.
  • Default: false
  • Example:
Useful for:
  • Docker/Kubernetes (logs to container stdout)
  • Systemd (logs to journald)
  • Log aggregation systems

--cors-allowed-origins <ORIGINS>

Comma-separated list of allowed CORS origins.
  • Default: * (all origins)
  • Example:
For production, always restrict CORS to your specific domains.

--runtime-threads <N>

Number of JavaScript isolates/workers for WASM runtime.
  • Default: Number of CPU cores
  • Environment variable: RUNTIME_THREADS
  • Example:

Configuration Files

TrailBase uses Protocol Buffer text format for configuration.

config.textproto

Main configuration file in <data-dir>/config/config.textproto:

secrets.textproto

Sensitive values in <data-dir>/secrets/secrets.textproto:
Protect secrets.textproto with strict file permissions: chmod 600 secrets.textproto

Environment Variables

All configuration options can be set via environment variables with the TRAIL_ prefix.

Naming Convention

Environment variables follow this pattern:
Examples:
  • TRAIL_SERVER_APPLICATION_NAME
  • TRAIL_EMAIL_SMTP_HOST
  • TRAIL_EMAIL_SMTP_PORT
  • TRAIL_AUTH_AUTH_TOKEN_TTL_SEC
  • TRAIL_AUTH_OAUTH_PROVIDERS_GOOGLE_CLIENT_ID

Common Environment Variables

Server Configuration

Authentication

Email Configuration

OAuth Providers

For map fields like OAuth providers, use the provider name in uppercase:

Docker Environment Variables

Example docker-compose with environment variables:
docker-compose.yml

Other Subcommands

TrailBase includes additional subcommands for management:

Schema Export

Export JSON Schema for an API:
Modes:
  • insert - Schema for creating records
  • select - Schema for reading records
  • update - Schema for updating records

OpenAPI Export

Export OpenAPI specification:

Migrations

Create a new migration file:
Creates: traildepot/migrations/main/U<timestamp>__create_users_table.sql

Admin Management

Manage admin users:

User Management

Manage users from the command line:

Email Testing

Send test emails:

WASM Components

Manage WASM components:

Default Values

Key default values:
  • Data directory: ./traildepot
  • Server address: localhost:4000
  • Auth token TTL: 60 minutes (2 minutes in debug builds)
  • Refresh token TTL: 30 days
  • Log retention: 7 days
  • CORS origins: * (all origins)
  • Runtime threads: Number of CPU cores

Configuration Best Practices

Never commit secrets to version control. Use environment variables or encrypted secrets management.
After editing config.textproto, restart TrailBase and check logs for validation errors:
Include config.textproto and secrets.textproto in backups:
Always set the public URL for OAuth and email links to work correctly:

Troubleshooting

Configuration Not Loading

Check file paths and permissions:

Environment Variables Not Working

Verify the variable name follows the correct pattern:

OAuth Redirects Failing

Ensure --public-url matches your OAuth provider’s redirect URL:

Next Steps

Production Setup

Production checklist, security, and monitoring

Self-Hosting

Learn about deployment strategies and installation