Skip to main content

Overview

Zeus server configuration is managed through environment variables. This allows flexible deployment across different environments.

Environment Variables

Required

VariableDescriptionExample
DATABASE_URLPostgreSQL connection stringpostgres://localhost/zeus

Optional

VariableDescriptionDefault
PORTServer port3000
RUST_LOGLog levelinfo
JWT_SECRETJWT signing keyRandom generated

Configuration File

Create .env in the server directory:
# Database
DATABASE_URL=postgres://localhost/zeus

# Server
PORT=3000

# Logging
RUST_LOG=info

# Security (generate a strong secret)
JWT_SECRET=your-super-secret-key-min-32-chars

Docker Compose

Full configuration in docker-compose.yml:
version: '3.8'

services:
  postgres:
    image: postgres:14
    environment:
      POSTGRES_USER: zeus
      POSTGRES_PASSWORD: zeus_password
      POSTGRES_DB: zeus
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  server:
    build: ./server
    environment:
      DATABASE_URL: postgres://zeus:zeus_password@postgres/zeus
      PORT: 3000
      RUST_LOG: info
    ports:
      - "3000:3000"
    depends_on:
      - postgres

volumes:
  postgres_data:

Environments

Development

# .env.development
DATABASE_URL=postgres://localhost/zeus_dev
RUST_LOG=debug
PORT=3000

Staging

# .env.staging
DATABASE_URL=postgres://staging-db/zeus
RUST_LOG=info
PORT=3000

Production

# .env.production
DATABASE_URL=postgres://prod-db/zeus
RUST_LOG=warn
PORT=3000
JWT_SECRET=<strong-secret-key>

Logging Levels

LevelUse Case
errorErrors only
warnWarnings and errors
infoGeneral information (default)
debugDetailed debugging
traceVery verbose

Security Considerations

  1. Never commit .env files - Add to .gitignore
  2. Use strong JWT secrets - At least 32 characters
  3. Rotate secrets regularly - Especially in production
  4. Use TLS - Always in production
  5. Limit database permissions - Use dedicated user

Configuration in Code

Access configuration in Rust:
use std::env;

pub struct Config {
    pub database_url: String,
    pub port: u16,
    pub jwt_secret: String,
}

impl Config {
    pub fn from_env() -> Self {
        Self {
            database_url: env::var("DATABASE_URL")
                .expect("DATABASE_URL must be set"),
            port: env::var("PORT")
                .unwrap_or_else(|_| "3000".to_string())
                .parse()
                .expect("PORT must be a number"),
            jwt_secret: env::var("JWT_SECRET")
                .unwrap_or_else(|_| generate_secret()),
        }
    }
}