Configuration

Environment Variables

Server

VariableDefaultDescription
IP_SERVER127.0.0.1Listening IP address
PORT3000Server port
DEBUGfalseDebug mode (templates, logs, etc.)

⚠️ Production: Set DEBUG=false explicitly. In debug mode, detailed error pages are visible, potentially revealing sensitive information. Also, compiling with cargo build --release automatically disables debug assertions, but DEBUG=true may override this.


Database

Connection

VariableDefaultDescription
DATABASE_URLFull connection URL (takes priority over all component variables)
DB_ENGINEsqlitepostgres, mysql, mariadb, sqlite
DB_USERDB user (required except for SQLite)
DB_PASSWORDDB password (required except for SQLite)
DB_HOSTlocalhostDB host
DB_PORT5432 / 3306DB port (default depends on engine)
DB_NAMElocal_base.sqliteDatabase name

Connection pool

VariableDefaultDescription
DB_MAX_CONNECTIONS100Maximum pool size
DB_MIN_CONNECTIONS20Minimum pool size

Timeouts

VariableDefaultUnitDescription
DB_CONNECT_TIMEOUT2secondsConnection establishment timeout
DB_ACQUIRE_TIMEOUT500millisecondsPool acquire timeout
DB_IDLE_TIMEOUT300secondsIdle connection lifetime
DB_MAX_LIFETIME3600secondsMaximum connection lifetime

Logging

VariableDefaultDescription
DB_LOGGINGfalseEnable SQL query logging (true, 1, yes)

PostgreSQL (direct URL):

DATABASE_URL=postgres://user:password@localhost:5432/dbname

PostgreSQL (component variables):

DB_ENGINE=postgres
DB_USER=postgres
DB_PASSWORD=secret
DB_HOST=localhost
DB_PORT=5432
DB_NAME=runique

SQLite (dev):

DB_ENGINE=sqlite
DB_NAME=runique.db

Custom pool:

DB_MAX_CONNECTIONS=50
DB_MIN_CONNECTIONS=5
DB_CONNECT_TIMEOUT=5
DB_IDLE_TIMEOUT=600
DB_LOGGING=true

Templates & Assets

VariableDefaultDescription
TEMPLATES_DIRtemplatesTemplates directory
STATICFILES_DIRSstaticStatic assets directory
MEDIA_ROOTmediaMedia directory (uploads)
TEMPLATES_DIR=templates
STATICFILES_DIRS=static:demo-app/static
MEDIA_ROOT=uploads

Security

VariableDefaultDescription
SECRET_KEY(required)CSRF secret key (⚠️ CHANGE IN PROD!)
SECRET_KEY=your_secret_key_change_this_in_production

Allowed hosts are configured in the builder (main.rs), not via an environment variable:

.with_allowed_hosts(|h| h.enabled(true).host("example.com"))

Complete .env file

# ============================================================================
# SERVER CONFIGURATION
# ============================================================================
IP_SERVER=127.0.0.1
PORT=3000
DEBUG=true

# ============================================================================
# DATABASE CONFIGURATION
# ============================================================================
DATABASE_URL=postgres://postgres:password@localhost:5432/runique
DB_ENGINE=postgres
DB_USER=postgres
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=runique

# SQLite (Development only)
# DATABASE_URL=sqlite:runique.db?mode=rwc

# ============================================================================
# TEMPLATES & STATIC FILES
# ============================================================================
TEMPLATES_DIR=templates
STATICFILES_DIRS=static
MEDIA_ROOT=media

# ============================================================================
# SECURITY
# ============================================================================
SECRET_KEY=your_secret_key_here_change_in_production

Generate a secret key

# Python
python -c "import secrets; print(secrets.token_urlsafe(32))"

# OpenSSL
openssl rand -base64 32

Environment modes

Production

DEBUG=false
PORT=443
IP_SERVER=0.0.0.0
SECRET_KEY=<dynamically generated>
DATABASE_URL=postgres://user:pwd@prod-db.example.com:5432/runique

Development

DEBUG=true
PORT=3000
IP_SERVER=127.0.0.1
SECRET_KEY=any_dev_key
DATABASE_URL=sqlite:runique.db?mode=rwc

Testing

DEBUG=true
SECRET_KEY=test_key
DATABASE_URL=sqlite::memory: