Serverpod constructor
Serverpod(
- List<
String> args, - SerializationManagerServer serializationManager,
- EndpointDispatch endpoints, {
- AuthenticationHandler? authenticationHandler,
- HealthCheckHandler? healthCheckHandler,
Creates a new Serverpod.
Implementation
Serverpod(
List<String> args,
this.serializationManager,
this.endpoints, {
this.authenticationHandler,
this.healthCheckHandler,
}) {
_internalSerializationManager = internal.Protocol();
// Create a temporary log manager with default settings, until we have loaded settings from the database.
_logManager = LogManager(_defaultRuntimeSettings);
// Read command line arguments
try {
var argParser = ArgParser()
..addOption('mode',
abbr: 'm',
allowed: [
ServerpodRunMode.development,
ServerpodRunMode.staging,
ServerpodRunMode.production,
],
defaultsTo: ServerpodRunMode.development)
..addOption('server-id', abbr: 'i', defaultsTo: 'default');
var results = argParser.parse(args);
_runMode = results['mode'];
serverId = results['server-id'];
} catch (e) {
stdout.writeln('Unknown run mode, defaulting to development');
_runMode = ServerpodRunMode.development;
}
// Load passwords
_passwords = PasswordManager(runMode: runMode).loadPasswords() ?? {};
// Load config
config = ServerpodConfig(_runMode, serverId, _passwords);
// Setup database
databaseConfig = DatabasePoolManager(
serializationManager,
config.database,
);
// Setup Redis
if (config.redis.enabled) {
redisController = RedisController(
host: config.redis.host,
port: config.redis.port,
user: config.redis.user,
password: config.redis.password,
);
}
_caches = Caches(serializationManager, config, serverId, redisController);
server = Server(
serverpod: this,
serverId: serverId,
port: config.apiServer.port,
serializationManager: serializationManager,
databaseConfig: databaseConfig,
passwords: _passwords,
runMode: _runMode,
caches: caches,
authenticationHandler:
authenticationHandler ?? defaultAuthenticationHandler,
whitelistedExternalCalls: whitelistedExternalCalls,
endpoints: endpoints,
);
endpoints.initializeEndpoints(server);
// Setup future calls
_futureCallManager = FutureCallManager(server, serializationManager);
_instance = this;
// Setup health check manager
_healthCheckManager = HealthCheckManager(this);
// Create web server.
webServer = WebServer(serverpod: this);
// Print version
stdout.writeln(
'SERVERPOD version: $serverpodVersion mode: $_runMode time: ${DateTime.now().toUtc()}',
);
}