Skip to content

Environment Variables ​

Complete reference for all environment variables and secrets.

Required Secrets ​

These must be set via wrangler secret put:

ENCRYPTION_KEY ​

256-bit AES encryption key for protecting tenant provider API keys (Gemini and OpenAI) at rest.

bash
# Generate
openssl rand -hex 32

# Set
wrangler secret put ENCRYPTION_KEY
PropertyValue
RequiredYes
Format64 hex characters
Used forEncrypting tenant provider API keys (Gemini, OpenAI) in D1

ADMIN_TOKEN ​

Authentication token for admin API endpoints.

bash
# Generate
openssl rand -hex 32

# Set
wrangler secret put ADMIN_TOKEN
PropertyValue
RequiredYes (for admin features)
FormatAny secure string
Used for/admin/* endpoint authentication

SESSION_SECRET ​

Secret for signing session cookies in the web console.

bash
# Generate
openssl rand -hex 32

# Set
wrangler secret put SESSION_SECRET
PropertyValue
RequiredYes (for web console)
FormatAny secure string
Used forCookie signing

Configuration Variables ​

Set in wrangler.jsonc under vars:

ENVIRONMENT ​

Deployment environment identifier.

jsonc
{
  "vars": {
    "ENVIRONMENT": "production"
  }
}
PropertyValue
RequiredNo
Defaultdevelopment
Valuesdevelopment, staging, production
Used forEnvironment-specific behavior

LOG_LEVEL ​

Logging verbosity level.

jsonc
{
  "vars": {
    "LOG_LEVEL": "info"
  }
}
PropertyValue
RequiredNo
Defaultinfo
Valuesdebug, info, warn, error
Used forControlling log output

R2_PUBLIC_URL ​

Public URL prefix for R2 bucket access.

jsonc
{
  "vars": {
    "R2_PUBLIC_URL": "https://pub-xxx.r2.dev"
  }
}
PropertyValue
RequiredYes
FormatHTTPS URL
Used forGenerating public image URLs

CORS_ORIGINS ​

Allowed origins for CORS requests.

jsonc
{
  "vars": {
    "CORS_ORIGINS": "https://console.example.com,https://app.example.com"
  }
}
PropertyValue
RequiredNo
Default* (all origins)
FormatComma-separated URLs
Used forCORS header configuration

MAX_UPLOAD_SIZE_MB ​

Maximum file size for image uploads.

jsonc
{
  "vars": {
    "MAX_UPLOAD_SIZE_MB": "20"
  }
}
PropertyValue
RequiredNo
Default20
FormatInteger (MB)
Used forUpload validation

DEFAULT_RATE_LIMIT ​

Default rate limit for new tenants.

jsonc
{
  "vars": {
    "DEFAULT_RATE_LIMIT": "60"
  }
}
PropertyValue
RequiredNo
Default60
FormatInteger (requests/minute)
Used forNew tenant defaults

DEFAULT_QUOTA_MB ​

Default monthly storage quota for new tenants.

jsonc
{
  "vars": {
    "DEFAULT_QUOTA_MB": "10240"
  }
}
PropertyValue
RequiredNo
Default10240 (10 GB)
FormatInteger (MB)
Used forNew tenant defaults

Binding References ​

D1 Database ​

jsonc
{
  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "go-bananas-db",
      "database_id": "your-database-id"
    }
  ]
}

Code reference: env.DB

R2 Bucket ​

jsonc
{
  "r2_buckets": [
    {
      "binding": "R2_IMAGES",
      "bucket_name": "go-bananas-images"
    }
  ]
}

Code reference: env.R2_IMAGES

KV Namespaces ​

jsonc
{
  "kv_namespaces": [
    {
      "binding": "API_KEYS",
      "id": "your-kv-id"
    },
    {
      "binding": "TENANT_CONFIG",
      "id": "your-kv-id"
    }
  ]
}

Code references: env.API_KEYS, env.TENANT_CONFIG

Durable Objects ​

jsonc
{
  "durable_objects": {
    "bindings": [
      {
        "name": "MCP_OBJECT",
        "class_name": "GoBananasMcpAgent"
      }
    ]
  }
}

Code reference: env.MCP_OBJECT

Environment-Specific Configuration ​

Development ​

jsonc
// wrangler.jsonc
{
  "vars": {
    "ENVIRONMENT": "development",
    "LOG_LEVEL": "debug",
    "R2_PUBLIC_URL": "http://localhost:8787/r2"
  }
}

Staging ​

jsonc
// wrangler.jsonc
{
  "env": {
    "staging": {
      "vars": {
        "ENVIRONMENT": "staging",
        "LOG_LEVEL": "info",
        "R2_PUBLIC_URL": "https://staging-pub-xxx.r2.dev"
      }
    }
  }
}

Production ​

jsonc
// wrangler.jsonc
{
  "env": {
    "production": {
      "vars": {
        "ENVIRONMENT": "production",
        "LOG_LEVEL": "warn",
        "R2_PUBLIC_URL": "https://pub-xxx.r2.dev"
      }
    }
  }
}

Local Development ​

.dev.vars ​

For local development, create .dev.vars:

bash
# .dev.vars (not committed to git)
ENCRYPTION_KEY=your-64-char-hex-key
ADMIN_TOKEN=local-admin-token
SESSION_SECRET=local-session-secret

.env (for scripts) ​

bash
# .env
ENCRYPTION_KEY=your-64-char-hex-key

Environment Variable Validation ​

At startup, Go Bananas! validates required variables:

typescript
function validateEnv(env: Env): void {
  if (!env.ENCRYPTION_KEY || env.ENCRYPTION_KEY.length !== 64) {
    throw new Error('ENCRYPTION_KEY must be 64 hex characters');
  }

  if (!env.R2_PUBLIC_URL) {
    throw new Error('R2_PUBLIC_URL is required');
  }
}

Security Best Practices ​

Never Commit Secrets ​

Add to .gitignore:

.dev.vars
.env
*.pem
*.key

Rotate Secrets Regularly ​

bash
# Generate new key
NEW_KEY=$(openssl rand -hex 32)

# Update secret
wrangler secret put ENCRYPTION_KEY

# Re-encrypt existing data (if applicable)
npm run rotate-encryption-key

Use Different Keys Per Environment ​

bash
# Development
wrangler secret put ENCRYPTION_KEY --env development

# Staging
wrangler secret put ENCRYPTION_KEY --env staging

# Production
wrangler secret put ENCRYPTION_KEY --env production

Next Steps ​

Released under the MIT License.