ServerpodConfig.loadFromMap constructor
ServerpodConfig.loadFromMap(})
Creates a new ServerpodConfig from a configuration Map. Expects the Map to match the specified run mode.
Throws an exception if the configuration is missing required fields.
Implementation
factory ServerpodConfig.loadFromMap(
String runMode,
String? serverId,
Map<String, String> passwords,
Map configMap, {
Map<String, String> environment = const {},
Map<String, dynamic>? commandLineArgs,
}) {
serverId = _readServerId(configMap, environment, serverId);
final role = _readRole(configMap, environment, commandLineArgs);
final loggingMode = _readLoggingMode(
configMap,
environment,
commandLineArgs,
);
final applyMigrations = _readApplyMigrations(
configMap,
environment,
commandLineArgs,
);
final applyRepairMigration = _readApplyRepairMigration(
configMap,
environment,
commandLineArgs,
);
var apiConfig = _apiConfigMap(configMap, environment);
var apiServer = apiConfig != null
? ServerConfig._fromJson(apiConfig, ServerpodConfigMap.apiServer)
: _createDefaultApiServer();
var insightsConfig = _insightsConfigMap(configMap, environment);
// Extracted before [ServerConfig._fromJson], which validates strictly
// against the keys shared by all servers.
var insightsDatabaseAccessEnabled =
insightsConfig?.remove(
ServerpodServerConfigMap.enableDatabaseAccess,
) ==
true;
var insightsServer = insightsConfig != null
? ServerConfig._fromJson(
insightsConfig,
ServerpodConfigMap.insightsServer,
)
: null;
var webConfig = _webConfigMap(configMap, environment);
var webServer = webConfig != null
? ServerConfig._fromJson(webConfig, ServerpodConfigMap.webServer)
: null;
var maxRequestSize = _readMaxRequestSize(configMap, environment);
var serviceSecret = passwords[ServerpodPassword.serviceSecret.configKey];
var databaseConfig = _databaseConfigMap(configMap, environment);
var database = databaseConfig != null
? DatabaseConfig._fromJson(
databaseConfig,
passwords,
ServerpodConfigMap.database,
)
: null;
var redisConfig = _redisConfigMap(configMap, environment);
var redisEnabled =
redisConfig != null &&
(redisConfig[ServerpodEnv.redisEnabled.configKey] ?? true);
var redis = redisEnabled
? RedisConfig._fromJson(
redisConfig,
passwords,
ServerpodConfigMap.redis,
)
: null;
var sessionLogsConfigJson = _buildSessionLogsConfigMap(
configMap,
environment,
);
var sessionLogsConfig = sessionLogsConfigJson != null
? SessionLogConfig._fromJson(
sessionLogsConfigJson,
ServerpodConfigMap.sessionLogs,
databaseEnabled: database != null,
runMode: runMode,
)
: null;
var futureCallConfigJson = _buildFutureCallConfigMap(
configMap,
environment,
);
var futureCallConfig = futureCallConfigJson != null
? FutureCallConfig._fromJson(
futureCallConfigJson,
ServerpodConfigMap.futureCall,
)
: const FutureCallConfig();
var futureCallExecutionEnabled = _readIsFutureCallExecutionEnabled(
configMap,
environment,
);
var validateHeaders = _readValidateHeaders(configMap, environment);
var websocketPingInterval = _readWebsocketPingInterval(
configMap,
environment,
);
var allowedOrigins = _readAllowedOrigins(
configMap,
environment,
);
var authCookieConfigJson = _buildAuthCookieConfigMap(
configMap,
environment,
);
var authCookie = authCookieConfigJson != null
? WebAuthCookieConfig._fromJson(authCookieConfigJson)
: null;
return ServerpodConfig(
runMode: runMode,
serverId: serverId,
role: role,
loggingMode: loggingMode,
applyMigrations: applyMigrations,
applyRepairMigration: applyRepairMigration,
apiServer: apiServer,
maxRequestSize: maxRequestSize,
insightsServer: insightsServer,
insightsDatabaseAccessEnabled: insightsDatabaseAccessEnabled,
webServer: webServer,
database: database,
redis: redis,
serviceSecret: serviceSecret,
sessionLogs: sessionLogsConfig,
futureCall: futureCallConfig,
futureCallExecutionEnabled: futureCallExecutionEnabled,
validateHeaders: validateHeaders,
websocketPingInterval: websocketPingInterval,
allowedOrigins: allowedOrigins,
authCookie: authCookie,
);
}