Skip to content

Config Section

The Config section controls how the configuration file itself is processed.

json
{
  "Config": {
    "ExposeAsEndpoint": null,
    "AddEnvironmentVariables": false,
    "ParseEnvironmentVariables": true,
    "EnvFile": null
  }
}

Settings Reference

SettingTypeDefaultDescription
ExposeAsEndpointstringnullExpose current configuration to an endpoint for debugging. Set to a path like "/config" to enable. Passwords in connection strings are not exposed.
AddEnvironmentVariablesboolfalseAllow environment variables to override configuration settings.
ParseEnvironmentVariablesbooltrueParse {ENV_VAR_NAME} placeholders in config values and replace with environment variable values.
EnvFilestringnullPath to a .env file for loading environment variables. See below.

Environment Variable Override

When AddEnvironmentVariables is true, environment variables can override any configuration setting. Use double underscores for nested keys:

bash
# Override ConnectionStrings.Default
export ConnectionStrings__Default="Host=production-server;..."

# Override NpgsqlRest.UrlPathPrefix
export NpgsqlRest__UrlPathPrefix="/v2/api"

Environment Variable Parsing

When ParseEnvironmentVariables is true (default), you can use {ENV_VAR} syntax anywhere in configuration values:

json
{
  "ConnectionStrings": {
    "Default": "Host={PGHOST};Port={PGPORT};Database={PGDATABASE};Username={PGUSER};Password={PGPASSWORD}"
  }
}

This allows sensitive values to be kept in environment variables rather than in the configuration file.

Loading from .env File

When AddEnvironmentVariables or ParseEnvironmentVariables is true and EnvFile is set, the application will load environment variables from the specified file:

json
{
  "Config": {
    "AddEnvironmentVariables": false,
    "ParseEnvironmentVariables": true,
    "EnvFile": ".env"
  }
}

The .env file format supports:

  • KEY=VALUE pairs (one per line)
  • Comments (lines starting with #)
  • Quoted values (both single and double quotes)

Example .env file:

# Database connection settings
PGHOST=localhost
PGPORT=5432
PGDATABASE=example_db
PGUSER=postgres
PGPASSWORD=postgres

The variables are loaded into the environment and made available for configuration parsing with the {ENV_VAR_NAME} syntax.

Exposing Configuration

For debugging purposes, you can expose the current configuration as an endpoint:

json
{
  "Config": {
    "ExposeAsEndpoint": "/config"
  }
}

This creates a GET /config endpoint that returns the current configuration as JSON. Passwords in connection strings are automatically redacted.

Next Steps

Comments

Released under the MIT License.