Skip to main content
Version: Next

Configurations

Serverpod can be configured in a few different ways. The minimum required settings to provide is the configuration for the API server. If no settings are provided at all, the default settings for the API server are used.

Configuration options

There are three different ways to configure Serverpod: with environment variables, via yaml config files, or by supplying the dart configuration object to the Serverpod constructor. The environment variables take precedence over the yaml configurations but both can be used simultaneously. The dart configuration object will override any environment variable or config file. The tables show all available configuration options provided in the Serverpod core library.

Environment variableConfig fileDefaultDescription
SERVERPOD_API_SERVER_PORTapiServer.port8080The port number for the API server
SERVERPOD_API_SERVER_PUBLIC_HOSTapiServer.publicHostlocalhostThe public host address of the API server
SERVERPOD_API_SERVER_PUBLIC_PORTapiServer.publicPort8080The public port number for the API server
SERVERPOD_API_SERVER_PUBLIC_SCHEMEapiServer.publicSchemehttpThe public scheme (http/https) for the API server
SERVERPOD_INSIGHTS_SERVER_PORTinsightsServer.port-The port number for the Insights server
SERVERPOD_INSIGHTS_SERVER_PUBLIC_HOSTinsightsServer.publicHost-The public host address of the Insights server
SERVERPOD_INSIGHTS_SERVER_PUBLIC_PORTinsightsServer.publicPort-The public port number for the Insights server
SERVERPOD_INSIGHTS_SERVER_PUBLIC_SCHEMEinsightsServer.publicScheme-The public scheme (http/https) for the Insights server
SERVERPOD_WEB_SERVER_PORTwebServer.port-The port number for the Web server
SERVERPOD_WEB_SERVER_PUBLIC_HOSTwebServer.publicHost-The public host address of the Web server
SERVERPOD_WEB_SERVER_PUBLIC_PORTwebServer.publicPort-The public port number for the Web server
SERVERPOD_WEB_SERVER_PUBLIC_SCHEMEwebServer.publicScheme-The public scheme (http/https) for the Web server
SERVERPOD_DATABASE_HOSTdatabase.host-The host address of the database
SERVERPOD_DATABASE_PORTdatabase.port-The port number for the database connection
SERVERPOD_DATABASE_NAMEdatabase.name-The name of the database
SERVERPOD_DATABASE_USERdatabase.user-The user name for database authentication
SERVERPOD_DATABASE_REQUIRE_SSLdatabase.requireSslfalseIndicates if SSL is required for the database
SERVERPOD_DATABASE_IS_UNIX_SOCKETdatabase.isUnixSocketfalseSpecifies if the database connection is a Unix socket
SERVERPOD_REDIS_HOSTredis.host-The host address of the Redis server
SERVERPOD_REDIS_PORTredis.port-The port number for the Redis server
SERVERPOD_REDIS_USERredis.user-The user name for Redis authentication
SERVERPOD_REDIS_ENABLEDredis.enabledfalseIndicates if Redis is enabled
SERVERPOD_MAX_REQUEST_SIZEmaxRequestSize524288The maximum size of requests allowed in bytes
SERVERPOD_SESSION_PERSISTENT_LOG_ENABLEDsessionLogs.persistentEnabled-Enables or disables logging session data to the database. Defaults to true if a database is configured, otherwise false.
SERVERPOD_SESSION_CONSOLE_LOG_ENABLEDsessionLogs.consoleEnabled-Enables or disables logging session data to the console. Defaults to true if no database is configured, otherwise false.
Environment variablePasswords fileDefaultDescription
SERVERPOD_DATABASE_PASSWORDdatabase-The password for the database
SERVERPOD_SERVICE_SECRETserviceSecret-The token used to connect with insights must be at least 20 chars
SERVERPOD_REDIS_PASSWORDredis-The password for the Redis server

Config file example

The config file should be named after the run mode you start the server in and it needs to be placed inside the config directory in the root of the server project. As an example, you have the config/development.yaml that will be used when running in the development run mode.

apiServer:
port: 8080
publicHost: localhost
publicPort: 8080
publicScheme: http

insightsServer:
port: 8081
publicHost: localhost
publicPort: 8081
publicScheme: http

webServer:
port: 8082
publicHost: localhost
publicPort: 8082
publicScheme: http

database:
host: localhost
port: 8090
name: database_name
user: postgres

redis:
enabled: false
host: localhost
port: 8091

maxRequestSize: 524288

sessionLogs:
persistentEnabled: true
consoleEnabled: true

Passwords file example

The password file contains the secrets used by the server to connect to different services but you can also supply your secrets if you want. This file is structured with a common shared section, any secret put here will be used in all run modes. The other sections are the names of the run modes followed by respective key/value pairs.

shared:
myCustomSharedSecret: 'secret_key'

development:
database: 'development_password'
redis: 'development_password'
serviceSecret: 'development_service_secret'

production:
database: 'production_password'
redis: 'production_password'
serviceSecret: 'production_service_secret'

Dart config object example

To configure Serverpod in Dart you simply pass an instance of the ServerpodConfig class to the Serverpod constructor. This config will override any environment variables or config files present. The Serverpod constructor is normally used inside the run function in your server.dart file. At a minimum, the apiServer has to be provided.

Serverpod(
args,
Protocol(),
Endpoints(),
config: ServerpodConfig(
apiServer: ServerConfig(
port: 8080,
publicHost: 'localhost',
publicPort: 8080,
publicScheme: 'http',
),
insightsServer: ServerConfig(
port: 8081,
publicHost: 'localhost',
publicPort: 8081,
publicScheme: 'http',
),
webServer: ServerConfig(
port: 8082,
publicHost: 'localhost',
publicPort: 8082,
publicScheme: 'http',
),
),
);

Default

If no yaml config files exist, no environment variables are configured and no dart config file is supplied this default configuration will be used.

ServerpodConfig(
apiServer: ServerConfig(
port: 8080,
publicHost: 'localhost',
publicPort: 8080,
publicScheme: 'http',
),
);