Skip to main content
Campus uses environment variables to configure various aspects of the application. All variables have sensible defaults and are optional unless otherwise noted.

Configuration File

Environment variables are defined in .env.example at the root of the repository. Copy this file to .env for local development:
cp .env.example .env
Never commit .env files to version control. They may contain sensitive credentials.

PocketBase Configuration

POCKETBASE_URL

POCKETBASE_URL
string
default:"https://rede-campus.up.railway.app"
The URL where PocketBase is hosted. By default, the app connects to the Railway-hosted instance.When to override:
  • Using a local PocketBase instance for development
  • Self-hosting PocketBase separately from the main application
  • Testing against a staging environment
Examples:
# Use local PocketBase (development)
POCKETBASE_URL=http://127.0.0.1:8090

# Use custom hosted instance
POCKETBASE_URL=https://pocketbase.example.com
In Docker deployments, this variable affects server-side requests only. Browser requests use same-origin (proxied by Caddy).

Analytics Configuration

PUBLIC_ENABLE_ANALYTICS

PUBLIC_ENABLE_ANALYTICS
boolean
default:"false"
Enables or disables analytics tracking throughout the application.Values:
  • true - Enable analytics
  • false - Disable analytics (default)
Example:
PUBLIC_ENABLE_ANALYTICS=true

PUBLIC_ANALYTICS_SAMPLE_RATE

PUBLIC_ANALYTICS_SAMPLE_RATE
number
default:"1"
The sampling rate for analytics events. Controls what percentage of events are tracked.Values:
  • 1 - Track 100% of events (default)
  • 0.5 - Track 50% of events
  • 0.1 - Track 10% of events
Useful for reducing analytics load in high-traffic scenarios.Example:
# Track 50% of analytics events
PUBLIC_ANALYTICS_SAMPLE_RATE=0.5

Support Configuration

PUBLIC_SUPPORT_EMAIL

PUBLIC_SUPPORT_EMAIL
string
When set, displays a support email link on error pages and help sections.Example:
PUBLIC_SUPPORT_EMAIL=[email protected]
If not set, no support contact will be displayed on error pages.

Media Upload Configuration

MEDIA_MAX_IMAGE_SIZE_MB

MEDIA_MAX_IMAGE_SIZE_MB
number
default:"10"
Maximum file size allowed for image uploads, in megabytes.Example:
# Allow up to 20MB images
MEDIA_MAX_IMAGE_SIZE_MB=20
Large file sizes may impact upload performance and storage costs. Consider your hosting platform’s limits.

MEDIA_MAX_IMAGE_COUNT

MEDIA_MAX_IMAGE_COUNT
number
default:"10"
Maximum number of images that can be uploaded in a single request or post.Example:
# Allow up to 20 images per post
MEDIA_MAX_IMAGE_COUNT=20

MEDIA_MAX_VIDEO_SIZE_MB

MEDIA_MAX_VIDEO_SIZE_MB
number
default:"500"
Maximum file size allowed for video uploads, in megabytes.Example:
# Allow up to 1GB videos
MEDIA_MAX_VIDEO_SIZE_MB=1000
Video files can be very large. Ensure your hosting platform supports large file uploads and has sufficient storage capacity.

MEDIA_MAX_VIDEO_DURATION_SECONDS

MEDIA_MAX_VIDEO_DURATION_SECONDS
number
default:"300"
Maximum duration allowed for video uploads, in seconds.Default: 300 seconds (5 minutes)Example:
# Allow up to 10 minute videos
MEDIA_MAX_VIDEO_DURATION_SECONDS=600

Runtime Environment Variables

PORT

PORT
number
default:"8080"
The port that Caddy will listen on for incoming HTTP requests. This is the external-facing port.Automatically set by:
  • Railway
  • Heroku
  • Most PaaS platforms
Example:
PORT=3000
In Docker deployments, remember to update your port mapping:
docker run -p 3000:3000 -e PORT=3000 campus:latest

NODE_ENV

NODE_ENV
string
default:"production"
The Node.js environment mode. Automatically set to production in the Docker image.Values:
  • production - Production mode (default in Docker)
  • development - Development mode
  • test - Test mode
Do not set to development in production deployments. This enables debugging features and reduces performance.

Example Configurations

Development (Local)

# .env
POCKETBASE_URL=http://127.0.0.1:8090
PUBLIC_ENABLE_ANALYTICS=false
PUBLIC_SUPPORT_EMAIL=dev@localhost
MEDIA_MAX_IMAGE_SIZE_MB=5
MEDIA_MAX_IMAGE_COUNT=5
MEDIA_MAX_VIDEO_SIZE_MB=100
MEDIA_MAX_VIDEO_DURATION_SECONDS=60

Production (Docker)

# Production environment variables
PORT=8080
PUBLIC_ENABLE_ANALYTICS=true
PUBLIC_ANALYTICS_SAMPLE_RATE=1
PUBLIC_SUPPORT_EMAIL=[email protected]
MEDIA_MAX_IMAGE_SIZE_MB=10
MEDIA_MAX_IMAGE_COUNT=10
MEDIA_MAX_VIDEO_SIZE_MB=500
MEDIA_MAX_VIDEO_DURATION_SECONDS=300

Railway Deployment

# Railway automatically sets PORT
# Only configure application-specific variables
PUBLIC_ENABLE_ANALYTICS=true
PUBLIC_ANALYTICS_SAMPLE_RATE=0.5
PUBLIC_SUPPORT_EMAIL=[email protected]
MEDIA_MAX_IMAGE_SIZE_MB=15
MEDIA_MAX_VIDEO_SIZE_MB=750

Setting Environment Variables

Docker Run

docker run -d \
  -e PUBLIC_ENABLE_ANALYTICS=true \
  -e MEDIA_MAX_IMAGE_SIZE_MB=20 \
  -e [email protected] \
  campus:latest

Docker Compose

services:
  campus:
    image: campus:latest
    environment:
      - PUBLIC_ENABLE_ANALYTICS=true
      - MEDIA_MAX_IMAGE_SIZE_MB=20
      - [email protected]

Railway

  1. Go to your project dashboard
  2. Click on “Variables” tab
  3. Add each variable as a key-value pair
  4. Redeploy for changes to take effect

Fly.io

Set secrets using the Fly CLI:
fly secrets set PUBLIC_ENABLE_ANALYTICS=true
fly secrets set MEDIA_MAX_IMAGE_SIZE_MB=20
fly secrets set [email protected]

Validation

Campus validates environment variables at startup. If any required variables are missing or invalid, the application will log an error and may fail to start. Check logs for validation errors:
# Docker
docker logs campus

# Railway
railway logs

# Fly.io
fly logs

Security Best Practices

Never expose sensitive environment variables in client-side code. Only variables prefixed with PUBLIC_ are safe to expose to the browser.
  1. Never commit .env files - Add to .gitignore
  2. Use platform secrets - For production deployments, use your platform’s secret management
  3. Rotate credentials - Regularly update sensitive values
  4. Limit access - Only grant environment variable access to necessary team members
  5. Audit changes - Track who changes environment variables and when

Next Steps

Build docs developers (and LLMs) love