Skip to Content
DocsSelf-HostingConfiguration

Configuration

Environment variables for the Pug backend and dashboard. Copy .env.example from each repo as the starting point.

Backend (cotton)

git clone git@github.com:fivebitsio/cotton.git cd cotton cp .env.example .env

Database

VariableRequiredDescription
DATABASE_URLYesPostgres write connection string
DATABASE_READ_URLNoPostgres read replica (falls back to write URL)
DATABASE_URL=postgres://pug:password@localhost:5432/pug?sslmode=disable DATABASE_READ_URL=postgres://pug:password@localhost:5433/pug?sslmode=disable

Analytics storage

VariableRequiredDescription
CLICKHOUSE_URLYesClickHouse HTTP connection
CLICKHOUSE_URL=http://default:@localhost:8123/pug

Message queue

VariableRequiredDescription
NATS_URLYesNATS server URL
NATS_URL=nats://localhost:4222

Authentication

VariableRequiredDescription
JWT_SECRETYesSecret for signing dashboard JWTs — use a long random string
MAGIC_LINK_SECRETYesSecret for magic link tokens
OAUTH_GOOGLE_CLIENT_IDNoGoogle OAuth client ID
OAUTH_GOOGLE_CLIENT_SECRETNoGoogle OAuth client secret

Generate secrets:

openssl rand -hex 32

Never reuse secrets between environments.

Server

VariableRequiredDescription
PORTNoAPI server port (default 8080)
ENVNodevelopment or production
LOG_LEVELNodebug, info, warn, error

Email

Configure SMTP for magic links and transactional email:

VariableRequiredDescription
SMTP_HOSTNoSMTP server hostname
SMTP_PORTNoSMTP port (default 587)
SMTP_USERNoSMTP username
SMTP_PASSWORDNoSMTP password
SMTP_FROMNoFrom address for transactional email

Org-specific email providers can override these via OrgEmailProvidersService in the dashboard.

Dashboard (cotton-ui)

git clone git@github.com:fivebitsio/cotton-ui.git cd cotton-ui cp .env.example .env
VariableRequiredDescription
VITE_API_URLYesConnect RPC endpoint (e.g. http://localhost:8080)
VITE_GOOGLE_OAUTH_ENABLEDNoSet true to show Google sign-in button
VITE_API_URL=http://localhost:8080 VITE_GOOGLE_OAUTH_ENABLED=true

For production, set VITE_API_URL to your public API URL at build time.

Web SDK

Point the SDK at your self-hosted API:

init('PROJECT_ID', { apiKey: 'YOUR_SDK_API_KEY', endpoint: process.env.NEXT_PUBLIC_PUG_API_URL // e.g. https://api.yourcompany.com })

No SDK code changes required — only the endpoint option.

Google OAuth setup

  1. Create a project in Google Cloud Console 
  2. Enable the Google+ API
  3. Create OAuth 2.0 credentials (Web application)
  4. Add authorized redirect URI: https://your-api.example.com/auth/google/callback
  5. Set OAUTH_GOOGLE_CLIENT_ID and OAUTH_GOOGLE_CLIENT_SECRET in cotton .env
  6. Set VITE_GOOGLE_OAUTH_ENABLED=true in cotton-ui .env

Secrets management

Do not commit .env files to version control. In production:

  • Use a secrets manager (AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager)
  • Inject secrets as environment variables at container startup
  • Rotate JWT_SECRET and API keys on a schedule

Verifying configuration

After starting the stack:

# API health curl http://localhost:8080/health # Send a test event curl -X POST http://localhost:8080/events.v1.EventsService/BatchCreate \ -H "Authorization: Bearer YOUR_SDK_API_KEY" \ -H "x-project-id: YOUR_PROJECT_ID" \ -H "Content-Type: application/json" \ -H "Connect-Protocol-Version: 1" \ -d '{"events":[{"name":"test_event"}]}'

See .env.example in each repo for the complete variable list.

Further reading

Last updated on