Environment
Env Vars
Environment variables are evaluated based on the following priority to allow flexibility when running in production, when the earliest priority is met, evaluation stops.
- cmd flags
- environment variables
.env
file
For example, when running go run . start -H 0.0.0.0
while having the value HOST=127.0.0.1
in a .env
file, the command value will be evaluated first and that will satisfy the HOST env var, thus preventing futher execution for that env var.
During development, it is recommended to use a .env
file. You can find a reference under /.env.sample` to get started.
To ease your development process, we've included a command to print the environment to better understand your app behaviour. Simply run go run . info env
. Together with go run . info features
, you should be able to get to the bottom of an issue.
Execution Modes
The service can run in one of two modes: production mode or development mode.
Development mode is activated using the -d
or --dev
flag. Running in this mode will lock the service host to 127.0.0.1
to avoid firewall issues when developing using MacOS. You can override this setting using -H 0.0.0.0
if needed.
Development mode will also activate useful middlewares that help print incoming request body, input data validation errors for debugging, and set the logger level to debug for ease of development. Everything else is identical to running in production mode.
You can change the behaviour of the service using flags, see the list of flags below for more.
List of all available env vars
Var Name | Required | Description |
---|---|---|
HOST | optional | service host address. default: 0.0.0.0 |
PROTECTED_API_PORT | optional | Service port. Default: 8080 |
PUBLIC_API_PORT | optional | Service port. Default: 8081 |
HIDDEN_API_PORT | optional | Service port. Default: 8079 |
DB_HOST | optional | Database host |
DB_PORT | optional | Database port |
DB_USER | optional | Database username |
DB_PASSWORD | optional | Database password |
DB_NAME | optional | Database name |
DB_TIMEZONE | optional | Database timezone. Required with Postgres platform |
DB_PLATFORM | optional | Enum: ["postgres", "mysql", "sqlite"]. default: "sqlite" |
KRATOS_PUBLIC_SERVICE | optional | Ory Kratos public API URL |
KRATOS_ADMIN_SERVICE | optional | Ory Kratos admin API URL |
KETO_READ_SERVICE | optional | Ory Keto read API URL |
KETO_WRITE_SERVICE | optional | Ory Keto write API URL |
REDIS_HOST | optional | Redis host URL. Required if Redis is enabled |
REDIS_PORT | optional | Redis port. Required if Redis is enabled |
REDIS_PASSWORD | optional | Redis password. Required if Redis is enabled |
LOG_LEVEL | optional | Enum: ["info", "warn", "debug", "error"]. default: "info" |
CORS_ALLOW_ORIGINS | optional | Allowed origins. Default: "*" |
REQUEST_TIMEOUT_DURATION | optional | Number in seconds. Default: "60" |
DISABLE_FEATURES | optional | List of features to disable in runtime, make sure its comma separated without spaces |