Configuration
Documentation / Configuration / The `.env` file

The `.env` file

The app's configuration is read from the .env file at the project root, then completed in code (builder). The full list of variables, with their defaults, is in Environment variables.

Complete examples

RUNIQUE_ENV sets how the application behaves; DEBUG only shows the detailed error pages. See Application & Server.

Development (SQLite)

IP_SERVER=127.0.0.1
PORT=3000
RUNIQUE_ENV=dev
DEBUG=true

SECRET_KEY=<generated by runique new>

DB_ENGINE=sqlite
DATABASE_URL="sqlite://data.db?mode=rwc"

?mode=rwc creates the file when it doesn't exist. The URL must start with sqlite://: a short form such as sqlite:data.db is refused ("Unsupported database URL scheme").

Development (PostgreSQL)

IP_SERVER=127.0.0.1
PORT=3000
RUNIQUE_ENV=dev
DEBUG=true

SECRET_KEY=<generated by runique new>

DB_ENGINE=postgres
DATABASE_URL=postgres://runique_user:password@localhost:5432/my_project

Or, instead of DATABASE_URL, the component variables:

DB_ENGINE=postgres
DB_USER=runique_user
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=my_project

When DATABASE_URL is set, it wins: the DB_* variables are ignored.

Production (behind a reverse proxy)

IP_SERVER=127.0.0.1
PORT=3000
RUNIQUE_ENV=prod
DEBUG=false

SECRET_KEY=<a key of this deployment's own>

DB_ENGINE=postgres
DATABASE_URL=postgres://runique_user:[email protected]:5432/my_project

ENFORCE_HTTPS=true

The proxy (Nginx, Caddy…) listens on 80/443 and handles TLS; Runique stays on an internal port. For Runique to handle TLS itself with no proxy, see Network & HTTP (ACME).

In production, Runique refuses to start when SECRET_KEY is weak, or when the password reset or the admin is on without .with_public_url(...).


Generating a secret key

runique new writes one when the project is created. To make another (leak, new deployment): any random string of 32 characters or more.

openssl rand -hex 32

What `.env` doesn't set

Allowed hosts, CSP, CORS, sessions and middlewares are configured in the builder (main.rs):

.middleware(|m| m.with_allowed_hosts(|h| h.host("example.com")))

See Builder.