serverpod-configuration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseServerpod Configuration
Serverpod 配置
Priority (highest wins): Dart config object > environment variables > YAML config files. The config uses YAML files that live in . Secrets are in or env vars with prefix.
config/config/passwords.yamlSERVERPOD_PASSWORD_优先级(最高优先级获胜):Dart 配置对象 > 环境变量 > YAML 配置文件。配置使用存储在目录下的YAML文件。密钥存储在中,或使用带有前缀的环境变量。
config/config/passwords.yamlSERVERPOD_PASSWORD_Run mode
运行模式
Config files by mode: , , , . Set via when starting server or (default: ).
config/development.yamlconfig/staging.yamlconfig/production.yamlconfig/test.yaml--modeSERVERPOD_RUN_MODEdevelopment按模式划分的配置文件:、、、。启动服务器时通过参数设置,或使用环境变量(默认值:)。
config/development.yamlconfig/staging.yamlconfig/production.yamlconfig/test.yaml--modeSERVERPOD_RUN_MODEdevelopmentAPI server (minimum)
API 服务器(最小配置)
yaml
apiServer:
port: 8080
publicHost: localhost
publicPort: 8080
publicScheme: httppublicHostpublicPortpublicSchemeyaml
apiServer:
port: 8080
publicHost: localhost
publicPort: 8080
publicScheme: httppublicHostpublicPortpublicSchemeDatabase
数据库
It is possible to use either PostgreSQL or SQLite as the database.
可以选择PostgreSQL或SQLite作为数据库。
PostgreSQL
PostgreSQL
yaml
database:
host: localhost
port: 8090
name: my_project
user: postgres
dataPath: .serverpod/development/pgdata # embedded database, see belowPassword in under run mode or . Optional: , , , .
passwords.yamlSERVERPOD_PASSWORD_databasesearchPathsmaxConnectionCountrequireSslisUnixSocketEmbedded PostgreSQL: with set, Serverpod launches and manages a PostgreSQL instance in that directory, so nothing has to be installed or run separately. New projects use it for development and testing. boots the same database on its own, without the server.
dataPathserverpod database start [--mode <mode>] [--port <port>]Without the database is external, and starts Docker Compose services when the project has a compose file and PostgreSQL is on localhost ( / override this).
dataPathserverpod start--docker--no-dockeryaml
database:
host: localhost
port: 8090
name: my_project
user: postgres
dataPath: .serverpod/development/pgdata # 嵌入式数据库,详见下文密码存储在对应运行模式下的中,或使用环境变量。可选配置:、、、。
passwords.yamlSERVERPOD_PASSWORD_databasesearchPathsmaxConnectionCountrequireSslisUnixSocket嵌入式PostgreSQL: 设置后,Serverpod会在该目录下启动并管理一个PostgreSQL实例,无需单独安装或运行。新项目在开发和测试阶段默认使用该模式。使用命令可以单独启动该数据库,无需启动服务器。
dataPathserverpod database start [--mode <mode>] [--port <port>]如果未设置,则使用外部数据库。当项目包含compose文件且PostgreSQL位于本地主机时,会启动Docker Compose服务(可通过 / 参数覆盖此行为)。
dataPathserverpod start--docker--no-dockerSQLite
SQLite
yaml
database:
filePath: my_project.sqliteNo password is needed for SQLite.
yaml
database:
filePath: my_project.sqliteSQLite无需密码。
Redis
Redis
redis.enabledredis.hostredis.portSERVERPOD_PASSWORD_redis配置项包括、、;密码通过环境变量设置。
redis.enabledredis.hostredis.portSERVERPOD_PASSWORD_redisSecrets (passwords.yaml)
密钥(passwords.yaml)
Structure: (all modes) + per-mode (, , etc.). Built-in keys: , , . Custom keys available via or .
shared:development:production:databaseredisserviceSecretsession.passwords['key']pod.getPassword('key')The built-in passwords also have dedicated environment variables: , and . Any password, built-in or custom, can also be set with the prefix.
SERVERPOD_DATABASE_PASSWORDSERVERPOD_REDIS_PASSWORDSERVERPOD_SERVICE_SECRETSERVERPOD_PASSWORD_bash
export SERVERPOD_PASSWORD_stripeApiKey=sk_live_... # → session.passwords['stripeApiKey']Never commit real secrets; use env vars in production.
结构:(所有模式通用)+ 各模式专属配置(、等)。内置密钥项:、、。自定义密钥可通过或获取。
shared:development:production:databaseredisserviceSecretsession.passwords['key']pod.getPassword('key')内置密钥也有对应的专属环境变量:、和。任何内置或自定义密钥都可以使用前缀的环境变量设置。
SERVERPOD_DATABASE_PASSWORDSERVERPOD_REDIS_PASSWORDSERVERPOD_SERVICE_SECRETSERVERPOD_PASSWORD_bash
export SERVERPOD_PASSWORD_stripeApiKey=sk_live_... # → session.passwords['stripeApiKey']请勿提交真实密钥;生产环境请使用环境变量。
generator.yaml
generator.yaml
In :
config/generator.yaml- :
type(default),server, ormoduleinternal - : path to client package
client_package_path - : map of module names + optional
modulesnickname - : test tools output path (remove to disable)
server_test_tools_path - : custom serializable class URIs
extraClasses - : e.g.
featuresdatabase: true/false
位于中的配置:
config/generator.yaml- :
type(默认)、server或moduleinternal - :客户端包路径
client_package_path - :模块名称映射,可附带可选的
modulesnickname - :测试工具输出路径(移除该配置可禁用)
server_test_tools_path - :自定义可序列化类的URI
extraClasses - :例如
featuresdatabase: true/false
Dart config override
Dart 配置覆盖
Pass to to skip file/env loading and use a Dart config object, with CLI flags still merged in.
config: ServerpodConfig(...)Serverpod(...)For tests, it is possible to use to adjust the loaded config after YAML/env/CLI processing.
configOverride: (config) => config.copyWith(...)在中传入,可跳过文件/环境加载,直接使用Dart配置对象,同时仍会合并CLI标志。
Serverpod(...)config: ServerpodConfig(...)测试时,可使用在YAML/环境/CLI处理完成后调整加载的配置。
configOverride: (config) => config.copyWith(...)TLS/SSL
TLS/SSL
Pass to with a that loads cert chain and private key. Set on , , and/or . Client: pass with trusted certificates to .
SecurityContextConfigServerpod(...)SecurityContextapiServerwebServerinsightsServerSecurityContextClient(...)将传入,其中包含加载证书链和私钥的。可在、和/或上设置。客户端需将带有受信任证书的传入。
SecurityContextConfigServerpod(...)SecurityContextapiServerwebServerinsightsServerSecurityContextClient(...)Reference files
参考文件
- — the full
references/environment-variables.mdenvironment variable table.SERVERPOD_* - — declaring the Flutter apps that
references/flutter-apps.mdcan launch.serverpod start
- —— 完整的
references/environment-variables.md环境变量列表。SERVERPOD_* - —— 声明
references/flutter-apps.md可启动的Flutter应用。serverpod start