### Launch a Serverpod Cloud Project Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/index.md Use this command to launch your first Serverpod project on Serverpod Cloud. It requires the `scloud` CLI to be installed and handles all infrastructure setup. ```bash scloud launch ``` -------------------------------- ### Shared Package Setup Example Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/03-serialization.md Create a dedicated Dart package for shared classes and add it as a dependency in your server and client pubspec.yaml files. ```text ├── my_project_client ├── my_project_flutter ├── my_project_server ├── my_project_shared ``` -------------------------------- ### Example Database Configuration in YAML Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/04-deploying-to-aws.md This YAML snippet shows how to configure database connection details, including enabling SSL. Update the host, port, name, user, and SSL requirement as per your setup. ```yaml database: host: redis.private-production.examplepod.com port: 5432 name: serverpod user: postgres requireSsl: true ``` -------------------------------- ### Install Serverpod CLI Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/index.md Installs the Serverpod command-line interface globally. Verify installation by running 'serverpod'. ```bash dart pub global activate serverpod_cli ``` ```bash serverpod ``` -------------------------------- ### Start Database and Apply Migrations Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/01-get-started/03-working-with-the-database.md Commands to start the Dockerized database and apply pending database migrations for the Serverpod application. ```bash cd magic_recipe_server docker compose up -d # Start the database container dart bin/main.dart --apply-migrations # Apply any pending migrations ``` -------------------------------- ### Start Local Development Server Source: https://github.com/serverpod/serverpod_docs/blob/main/README.md Starts a local development server for live preview of documentation changes. Changes are reflected live without server restarts. ```bash # Using npm $ npm start # Or if you have Make installed, use this make command $ make start ``` -------------------------------- ### Start the Serverpod Mini server Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/serverpod-mini.md Navigate to the server directory and run the main Dart file to start the server. This is essential for the client application to connect. ```bash cd myminipod/myminipod_server dart bin/main.dart ``` -------------------------------- ### scloud completion install usage Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/_generated/completion.md Details the usage of the `install` subcommand, which includes options for selecting the completion tool, executable name, and installation directory. ```console Install a command line completion script Usage: scloud completion install [arguments] -h, --help Print this usage information. -t, --tool (mandatory) The completion tool to target [completely] Use the `completely` tool (https://github.com/bashly-framework/completely) [carapace] Use the `carapace` tool (https://carapace.sh/) -e, --exec-name Override the name of the executable -d, --write-dir Override the directory to write the script to Run "scloud help" to see global options. ``` -------------------------------- ### Start Server Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/01-get-started/02-models-and-data.md Commands to start the Serverpod server using Docker Compose and Dart. ```bash cd magic_recipe_server docker compose up -d dart bin/main.dart ``` -------------------------------- ### Full Example with Referential Actions Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/03-relations/05-referential-actions.md This example demonstrates setting parentId to null on update and taking no action on delete when the parent 'example' is modified. ```yaml class: Example table: example fields: parentId: int?, relation(parent=example, onUpdate=SetNull, onDelete=NoAction) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/serverpod/serverpod_docs/blob/main/README.md Installs project dependencies using either npm or Make. Ensure Node.js is installed before running. ```bash $ cd serverpod_docs # Using npm $ npm install # Or if you have Make installed, use this make command $ make install ``` -------------------------------- ### Start Serverpod Server Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/04-archive/02-upgrade-to-one-point-two.md Start your Serverpod server to enable the repair migration system to fetch the live database schema. Warnings about schema mismatches are expected and can be ignored. ```dart dart run bin/main.dart ``` -------------------------------- ### Run Serverpod Server with Migrations Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/index.md Starts the Serverpod server and applies initial database migrations. Access the server at http://localhost:8080. ```bash cd my_project/my_project_server dart run bin/main.dart --apply-migrations ``` -------------------------------- ### Serverpod Cloud Launch Command Usage Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/_generated/launch.md This is the common command to launch and deploy Serverpod Cloud projects. If a project exists nearby, it redeploys; otherwise, it guides through setup. Use this command to initiate the deployment process for your Serverpod application. ```console Common command to launch and deploy Serverpod Cloud projects. If there already is a Serverpod Cloud project near the current directory it will redeploy the project (upload, build, and rollout in the cloud). Otherwise it will guide you through setting up a new Serverpod Cloud project. Usage: scloud launch [arguments] -h, --help Print this usage information. -p, --project The ID of the project. --[no-]pre-deploy-scripts Set up pre-deploy scripts. (defaults to on) --dart-version Overrides the Dart SDK version to use for building the project. Deployment options -c, --concurrency= Number of concurrent files processed when zipping the project. (defaults to "5") --dry-run Do not actually deploy, just print the deployment steps. --show-files Display the file tree that will be uploaded. -o, --output Save the deployment zip file to the specified path. Must end with .zip --[no-]await Await the deployment to finish while showing status progression. (defaults to on) Run "scloud help" to see global options. See the full documentation at: https://docs.serverpod.dev/cloud/reference/cli/commands/launch ``` -------------------------------- ### Install Markdown Linter Source: https://github.com/serverpod/serverpod_docs/blob/main/README.md Installs the markdownlint-cli globally for consistent markdown formatting. This is recommended for contributing to the documentation. ```bash # Using npm $ npm install -g markdownlint-cli # Or if you have Make installed, use this make command $ make install-linter ``` -------------------------------- ### Example Migration File Structure Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/11-migrations.md Illustrates the naming convention for migration files, including a timestamp and an optional tag. ```text ├── migrations │ └── 20231205080937028-v1-0-0 ``` -------------------------------- ### Install Carapace for Windows Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/04-shell-completion.md Use winget to install Carapace on Windows. ```powershell winget install carapace ``` -------------------------------- ### Install Carapace for Ubuntu/Debian Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/04-shell-completion.md Use apt to install Carapace on Ubuntu/Debian systems. ```bash sudo apt install carapace-bin ``` -------------------------------- ### Start Serverpod LSP Server Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/02-lsp.md Use this command to start the Serverpod Language Server Protocol server. This server provides diagnostics for YAML protocol files. ```bash serverpod language-server ``` -------------------------------- ### Apply Migrations on Server Startup Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/11-migrations.md Apply migrations automatically when the server starts. Ensure this is done in your project's `server` package directory. ```bash $ dart run bin/main.dart --apply-migrations ``` -------------------------------- ### Start Docker Compose for Testing Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/19-testing/01-get-started.md Before running tests, ensure your database and Redis instances are running. Use `docker compose up --build --detach` to start them in the background. ```bash docker compose up --build --detach ``` -------------------------------- ### Start Database with Docker Compose Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/index.md Starts the PostgreSQL database for your Serverpod project using Docker Compose. Run from the server directory. Use '-d' to run in detached mode. ```bash cd my_project/my_project_server docker compose up ``` ```bash cd my_project/my_project_server docker compose up -d ``` ```bash cd my_project/my_project_server docker compose down ``` -------------------------------- ### Example deployment status output Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/getting-started/launch.md This is an example of the output you might see when tracking a deployment. It indicates the successful completion of upload, build, infrastructure deployment, and service rollout. ```text Tracking my-app deployment 4583d0a1-3d0a-400e-a9a5-9880da6abc94 (Press Ctrl+C to exit) Upload successful. Cloud build successful. Infra deploy successful. Service rollout successful. 🚀 ``` -------------------------------- ### Verify Serverpod Cloud CLI Installation Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/getting-started/installation.md Run this command after installation to confirm that the `scloud` CLI is accessible and to check its version. ```bash scloud version ``` -------------------------------- ### Install Bash Completion with Completely Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/commands/completion/_completion.md Run this command to install the scloud completion script for bash using the Completely tool. The script is typically saved to `~/.local/share/bash-completion/completions/scloud.bash`. ```sh scloud completion install -t completely ``` -------------------------------- ### Install Serverpod Cloud CLI Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/getting-started/installation.md Use this command to install the `serverpod_cloud_cli` package, making the `scloud` command available in your terminal. ```bash dart install serverpod_cloud_cli ``` -------------------------------- ### Serverpod Server Initialization Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/14-scheduling/01-setup.md Initialize and start the Serverpod server, including protocol and endpoints. ```dart import 'package:serverpod/serverpod.dart'; import 'package:serverpod_auth_idp_server/core.dart'; import 'src/generated/protocol.dart'; import 'src/generated/endpoints.dart'; void run(List args) async { final pod = Serverpod( args, Protocol(), Endpoints(), ); await pod.start(); } ``` -------------------------------- ### Example Login Endpoint Implementation Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/10-custom-overrides.md An example of a login endpoint that authenticates a user and issues a custom authentication token. This endpoint is responsible for handling user credentials and returning a token to the client. ```dart class UserEndpoint extends Endpoint { Future login( Session session, String username, String password, ) async { var identifier = authenticateUser(session, username, password); if (identifier == null) return null; return issueMyToken(identifier, scopes: {}); } } ``` -------------------------------- ### Check Docker Installation Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/index.md Verify your Docker installation by running the 'docker info' command in your terminal. Ensure Docker is running, especially if using Docker Desktop. ```bash $ docker info ``` -------------------------------- ### Install Serverpod Carapace Completion Spec Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/04-shell-completion.md Installs the completion specification for Serverpod using Carapace. This command should be run in your terminal. ```bash serverpod completion install --tool carapace ``` -------------------------------- ### Basic SPA Setup with SpaRoute Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/08-single-page-apps.md Serve static files from a directory and fallback to index.html for client-side routing. The route path defaults to '/'. ```dart final webDir = Directory('web/app'); pod.webServer.addRoute( SpaRoute( webDir, fallback: File('web/app/index.html'), ), ); ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/07-configuration.md Example of a development configuration file (development.yaml) for Serverpod. This file defines settings for the API server, insights server, web server, database, Redis, request size, session logs, and future calls. ```yaml apiServer: port: 8080 publicHost: localhost publicPort: 8080 publicScheme: http websocketPingInterval: 30 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 maxConnectionCount: 10 redis: enabled: false host: localhost port: 8091 maxRequestSize: 524288 sessionLogs: persistentEnabled: true cleanupInterval: 24h retentionPeriod: 90d retentionCount: 100000 consoleEnabled: true consoleLogFormat: json futureCallExecutionEnabled: true futureCall: concurrencyLimit: 5 scanInterval: 2000 ``` -------------------------------- ### Start Local Docker Postgres Database Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/01-connection.md Use Docker Compose to build and start a detached Postgres instance for development. This command assumes a `docker-compose.yaml` file is present. ```bash $ docker compose up --build --detach ``` -------------------------------- ### Run a Defined Serverpod Script Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/03-run-scripts.md Execute a script defined in your `pubspec.yaml` by prefixing its name with `serverpod run`. For example, to run the 'start' script, use `$ serverpod run start`. ```bash $ serverpod run start ``` -------------------------------- ### Negating Complex Expressions Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/06-filter.md The `~` operator can also negate more complex, combined expressions. Example: fetch users who do not have a name starting with 'A' AND are not older than 25. ```dart await User.db.find( session, where: (t) => ~(t.name.like('A%') | t.age > 25) ); ``` -------------------------------- ### Create a new Serverpod Mini project Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/serverpod-mini.md Use this command to initialize a new Serverpod Mini project. The `--mini` flag specifies the lightweight version. ```bash serverpod create myminipod --mini ``` -------------------------------- ### OR Logical Operator for Complex Queries Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/06-filter.md Combine multiple filter conditions using the `|` operator for an 'OR' logic. Example: fetch users whose names start with 'A' or 'B'. ```dart await User.db.find( session, where: (t) => (t.name.like('A%') | t.name.like('B%')) ); ``` -------------------------------- ### Implement SimpleAuthKeyManager Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/11-legacy/05-custom-overrides.md Implement the `AuthenticationKeyManager` interface to manage authentication tokens. This example stores the token in memory and is suitable for testing. ```dart class SimpleAuthKeyManager extends AuthenticationKeyManager { String? _key; @override Future get() async { return _key; } @override Future put(String key) async { _key = key; } @override Future remove() async { _key = null; } } ``` -------------------------------- ### Custom Route for REST API Operations Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/01-overview.md Example of a custom route handler designed for REST API operations, specifying allowed HTTP methods (GET, POST). ```dart class UsersApiRoute extends Route { UsersApiRoute() : super(methods: {Method.get, Method.post}); @override Future handleCall(Session session, Request request) async { if (request.method == Method.get) { // List users } else { // Create user } } } ``` -------------------------------- ### Create Initial Serverpod Migration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/04-archive/02-upgrade-to-one-point-two.md Execute this command in your project's `server` package directory. The migration system will create a migration as if the database needs to be initialized from scratch. ```bash serverpod create-migration ``` -------------------------------- ### Suggested scloud.yaml for New Projects Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/scloud-yaml-schema.md This example shows a typical scloud.yaml generated for a new project. It includes a suggested `pre_deploy` script and an empty `post_deploy` script. ```yaml project: projectId: "my-app" dartSdk: "^3.10.3" scripts: pre_deploy: - "serverpod generate" post_deploy: [] ``` -------------------------------- ### Negated Case-Insensitive String Matching with notIlike Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/06-filter.md Use `notIlike` to exclude rows based on a case-insensitive string pattern. Example: fetch users whose names do not start with 'b' or 'B'. ```dart await User.db.find( session, where: (t) => t.name.notIlike('b%') ); ``` -------------------------------- ### Module-Provided Abstract Endpoint Example Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/01-working-with-endpoints.md Demonstrates how a module can provide an abstract endpoint interface that client applications can extend and use. ```dart abstract class AuthSessionEndpoint extends Endpoint { Future isAuthenticated(Session session) async { return session.isUserSignedIn; } Future logout(Session session, {required bool allSessions}) async { // Implementation... } } ``` ```dart class UserLoggedInWidget extends StatelessWidget { final Client client; UserLoggedInWidget({required this.client}); // Will throw if no concrete implementation of the endpoint exists. EndpointAuthSession get sessionEndpoint => client.getEndpointOfType(); @override Widget build(BuildContext context) { return FutureBuilder( future: sessionEndpoint.isAuthenticated(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); } else if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else if (snapshot.hasData && snapshot.data == true) { return Text('User is logged in'); } else { return Text('User is not logged in'); } }, ); } } ``` ```dart // Extend the module's abstract endpoint to expose it class SessionEndpoint extends AuthSessionEndpoint {} ``` -------------------------------- ### Manual Build and Deploy Documentation Source: https://github.com/serverpod/serverpod_docs/blob/main/README.md Executes a deployment script for building and deploying documentation. Requires access to the Serverpod Github `serverpod.github.io` repository and cloning it next to the `serverpod_web` repo. ```bash $ util/deploy ``` -------------------------------- ### Default ServerpodConfig Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/07-configuration.md Example of the default Serverpod configuration when no YAML files, environment variables, or Dart config are provided. This ensures a basic server setup with default API server settings. ```dart ServerpodConfig( apiServer: ServerConfig( port: 8080, publicHost: 'localhost', publicPort: 8080, publicScheme: 'http', ), ); ``` -------------------------------- ### Initialize Authentication Services Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/01-setup.md Configure authentication services in your main server.dart file using initializeAuthServices. This example sets up JWT token management. ```dart import 'package:serverpod/serverpod.dart'; import 'package:serverpod_auth_idp_server/core.dart'; import 'src/generated/protocol.dart'; import 'src/generated/endpoints.dart'; void run(List args) async { final pod = Serverpod( args, Protocol(), Endpoints(), ); // Set up authentication services // The `pod.getPassword()` will get the value from `config/passwords.yaml`. pod.initializeAuthServices( tokenManagerBuilders: [ JwtConfig( // Pepper used to hash the refresh token secret. refreshTokenHashPepper: pod.getPassword('jwtRefreshTokenHashPepper')!, // Algorithm used to sign the tokens (`hmacSha512` or `ecdsaSha512`). algorithm: JwtAlgorithm.hmacSha512( // Private key to sign the tokens. Must be a valid HMAC SHA-512 key. SecretKey(pod.getPassword('jwtHmacSha512PrivateKey')!), ) ), ], ); await pod.start(); } ``` -------------------------------- ### Case-Insensitive String Matching with ilike Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/06-filter.md Use `ilike` for case-insensitive string matching. It fetches rows where a string field matches a pattern, ignoring case. Example: find users whose names start with 'a' or 'A'. ```dart await User.db.find( session, where: (t) => t.name.ilike('a%') ); ``` -------------------------------- ### Upgrade Serverpod Mini to Full Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/02-upgrade-from-mini.md Run this command in your server directory to add the necessary configuration files for the full Serverpod version. Ensure you have backed up your project beforehand. ```bash serverpod create . ``` -------------------------------- ### Filter Routes by HTTP Method in Dart Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/02-routing.md Specify the allowed HTTP methods for a route by passing a set of `Method` enums to the `methods` parameter in the `Route` constructor. This example allows GET, POST, and DELETE requests. ```dart class UserRoute extends Route { UserRoute() : super( methods: {Method.get, Method.post, Method.delete}, ); // ... } ``` -------------------------------- ### Advanced Example: One-to-Many Relation with Bridge Table Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/03-relations/06-modules.md Illustrates a one-to-many relation using a bridge table, connecting a User model to a Company model. This setup is common for managing complex relationships between custom and module data. ```yaml class: User table: user fields: userInfo: module:auth:UserInfo?, relation age: int company: Company?, relation(name=company_employee) indexes: user_info_id_unique_idx: fields: userInfoId unique: true company_unique_idx: fields: companyId unique: true ``` ```yaml class: Company table: company fields: name: String employees: List?, relation(name=company_employee) ``` -------------------------------- ### Implement a Custom API Route in Dart Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/02-routing.md Extend the `Route` base class to create custom API endpoints. Implement `handleCall` to process requests, access request bodies, and return JSON responses. This example handles both GET and POST requests. ```dart class ApiRoute extends Route { ApiRoute() : super(methods: {Method.get, Method.post}); @override Future handleCall(Session session, Request request) async { // Access request method if (request.method == Method.post) { // Read request body final body = await request.readAsString(); final data = jsonDecode(body); // Process and return JSON response return Response.ok( body: Body.fromString( jsonEncode({'status': 'success', 'data': data}), mimeType: MimeType.json, ), ); } // Return data for GET requests return Response.ok( body: Body.fromString( jsonEncode({'message': 'Hello from API'}) ), ); } } ``` -------------------------------- ### Accessing Facebook APIs on Server Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/04-providers/05-facebook/02-configuration.md Demonstrates how to use the access token on the server-side to call Facebook Graph APIs. This example shows making an HTTP GET request to retrieve the user's friends list. Ensure the necessary permissions are configured in your Facebook App settings and requested during sign-in. ```dart import 'package:http/http.dart' as http; final facebookIdpConfig = FacebookIdpConfigFromPasswords( // Optional: Extract additional info from Facebook Graph APIs getExtraFacebookInfoCallback: (session, { required accountDetails, required accessToken, required transaction, }) async { // Use accessToken to call Facebook Graph APIs and store additional info // Example: Access user's friends list final response = await http.get( Uri.https('graph.facebook.com', '/v21.0/me/friends'), headers: {'Authorization': 'Bearer $accessToken'}, ); // Process response and store additional info in the database }, ); ``` -------------------------------- ### Apply Database Migrations for Apple Sign-in Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/04-providers/04-apple/04-troubleshooting.md Run `serverpod generate` and then apply the migrations using the provided command. This is necessary to create tables required for Apple sign-in, such as `serverpod_auth_idp_apple_account`. ```bash serverpod generate dart run bin/main.dart --apply-migrations ``` -------------------------------- ### Initialize gcloud CLI Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/03-deploying-to-gcr-console.md Run this command to initialize the Google Cloud CLI. This sets up authentication and default configurations. ```bash $ gcloud init ``` -------------------------------- ### Create New Serverpod Project Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/01-get-started/01-creating-endpoints.md Use this command to initialize a new Serverpod project, which includes server, client, and Flutter app packages. ```bash serverpod create magic_recipe ``` -------------------------------- ### Install Carapace for macOS Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/09-tools/04-shell-completion.md Use Homebrew to install Carapace on macOS. ```bash brew install carapace ``` -------------------------------- ### Create and Apply Database Migration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/01-setup.md Create a migration to initialize the database for new identity providers. This involves creating the migration file, starting the database container, and applying the migration. ```bash # Create the migration $ serverpod create-migration # Start the database container $ docker compose up --build --detach # Apply the migration $ dart run bin/main.dart --role maintenance --apply-migrations ``` -------------------------------- ### Create Serverpod Project (Mini) Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/05-tutorials/02-tutorials/02-real-time-communication.md Use this command to create a new Serverpod project without database support, suitable for real-time applications. ```bash serverpod create pixorama --mini ``` -------------------------------- ### Install Firebase Core and Auth Packages Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/11-legacy/04-providers/05-firebase.md Install the necessary Firebase packages for your Flutter project using the Flutter CLI. ```bash flutter pub add firebase_core firebase_auth firebase_ui_auth ``` -------------------------------- ### Create a new Serverpod Cloud project Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/commands/project/_project.md Use this command to create a new project on Serverpod Cloud. Include `--enable-db` if your project requires a database, or `--no-enable-db` if it does not. ```bash scloud project create my-project --enable-db ``` -------------------------------- ### Check Server Startup Completion Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/13-health-checks.md Use the /startupz endpoint to verify if the server has finished initializing, including migrations. Kubernetes waits for this to pass before enabling liveness and readiness probes. ```bash curl http://localhost:8080/startupz # Returns: 200 OK once startup is complete ``` -------------------------------- ### Install Firebase CLI and FlutterFire CLI Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/04-providers/06-firebase/01-setup.md Ensure you have the Firebase CLI and FlutterFire CLI installed globally for project configuration. ```bash npm install -g firebase-tools dart pub global activate flutterfire_cli ``` -------------------------------- ### Install Carapace for macOS Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/commands/completion/_completion.md If you are on macOS, use Homebrew to install the Carapace tool, which is a prerequisite for enabling Carapace-based completion for scloud. ```sh brew install carapace ``` -------------------------------- ### Initialize Terraform Configuration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/02-deploying-to-gce-terraform.md Run this command to download the Serverpod module and initialize your Terraform configuration before deploying infrastructure. ```bash $ terraform init ``` -------------------------------- ### Initialize Client and Session Manager Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/11-legacy/01-setup.md Set up the client to connect to the Serverpod and initialize the SessionManager for managing user authentication state. ```dart late SessionManager sessionManager; late Client client; void main() async { // Need to call this as we are using Flutter bindings before runApp is called. WidgetsFlutterBinding.ensureInitialized(); // The android emulator does not have access to the localhost of the machine. // const ipAddress = '10.0.2.2'; // Android emulator ip for the host // On a real device replace the ipAddress with the IP address of your computer. const ipAddress = 'localhost'; // Sets up a singleton client object that can be used to talk to the server from // anywhere in our app. The client is generated from your server code. // The client is set up to connect to a Serverpod running on a local server on // the default port. You will need to modify this to connect to staging or // production servers. client = Client( 'http://$ipAddress:8080/', authenticationKeyManager: FlutterAuthenticationKeyManager(), )..connectivityMonitor = FlutterConnectivityMonitor(); // The session manager keeps track of the signed-in state of the user. You // can query it to see if the user is currently signed in and get information // about the user. sessionManager = SessionManager( caller: client.modules.auth, ); await sessionManager.initialize(); runApp(MyApp()); } ``` -------------------------------- ### Print Serverpod Cloud CLI Version Source: https://github.com/serverpod/serverpod_docs/blob/main/cloud_docs/reference/cli/_generated/version.md Prints the installed version of the Serverpod Cloud CLI. Use this command to verify your CLI installation. ```console Prints the version of the Serverpod Cloud CLI. Usage: scloud version [arguments] -h, --help Print this usage information. Run "scloud help" to see global options. See the full documentation at: https://docs.serverpod.dev/cloud/reference/cli/commands/version ``` -------------------------------- ### Create a Serverpod Migration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/11-migrations.md Run this command in your project's `server` package directory to generate a new database migration. It compares current schema requirements with the latest migration. ```bash $ serverpod create-migration ``` -------------------------------- ### Enable all experimental features Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/22-experimental.md Use the `--experimental-features=all` flag with the `serverpod generate` command to enable all available experimental features. ```bash $ serverpod generate --experimental-features=all ``` -------------------------------- ### Create a Custom Serverpod Module Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/10-modules.md Use the 'serverpod create' command with the '--template module' flag to generate the basic structure for a new Serverpod module. ```bash $ serverpod create --template module my_module ``` -------------------------------- ### Check Flutter Installation Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/index.md Verify your Flutter installation by running the 'flutter doctor' command in your terminal. This command checks your Flutter environment and displays a report of the current status. ```bash $ flutter doctor ``` -------------------------------- ### Initialize Serverpod Client and Service Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/04-providers/10-custom-providers/02-oauth2-utility/02-creating-an-oauth2-based-identity-provider.md Set up the Serverpod client and initialize the custom authentication service in your application's main function. This ensures that the client is ready to handle authentication requests. ```dart import 'package:flutter/material.dart'; import 'package:serverpod_auth_idp_flutter/serverpod_auth_idp_flutter.dart'; import 'package:serverpod_flutter/serverpod_flutter.dart'; import 'package:your_client/your_client.dart'; import 'my_provider_service.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialize Serverpod client final client = Client('http://localhost:8080/') ..connectivityMonitor = FlutterConnectivityMonitor() ..authSessionManager = FlutterAuthSessionManager(); await client.auth.initialize(); // Initialize MyProvider service MyProviderService.instance.initialize(); runApp(MyApp(client: client)); } ``` -------------------------------- ### Create Serverpod Repair Migration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/04-archive/02-upgrade-to-one-point-two.md After starting the server, run this command in your project's `server` package directory to create a repair migration that aligns your live database schema with the newly created migration. ```bash serverpod create-repair-migration ``` -------------------------------- ### Run Serverpod Server with Flutter Web App Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/09-flutter-web.md This snippet shows a complete server.dart file. It initializes Serverpod, configures it to serve a Flutter web app from the 'web/app' directory, and starts the server. Ensure your Flutter app is built and placed in the specified directory. ```dart import 'dart:io'; import 'package:serverpod/serverpod.dart'; import 'src/generated/protocol.dart'; import 'src/generated/endpoints.dart'; void run(List args) async { final pod = Serverpod(args, Protocol(), Endpoints()); final flutterAppDir = Directory('web/app'); if (!flutterAppDir.existsSync()) { print('Warning: Flutter web app not found at ${flutterAppDir.path}'); print('Build your Flutter app and copy it to web/app/'); } else { pod.webServer.addRoute(FlutterRoute(flutterAppDir)); } await pod.start(); } ``` -------------------------------- ### Start Server in Production Mode with ID 2 Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/05-general.md Use this command to start the Serverpod server in production mode with a specific server ID. This is useful when running multiple servers in a cluster. ```bash $ dart bin/main.dart --mode production --server-id 2 ``` -------------------------------- ### Initialize and Apply Terraform Configuration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/04-deploying-to-aws.md Run these Terraform commands to initialize the project and apply the infrastructure changes. `terraform init` is only needed for the first deployment. ```bash $ terraform init $ terraform apply ``` -------------------------------- ### YAML Passwords File Example Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/07-configuration.md Example of a passwords file for Serverpod, separating shared secrets from run-mode-specific secrets. This file is used to manage sensitive information like database and Redis passwords. ```yaml shared: myCustomSharedSecret: 'secret_key' development: database: 'development_password' redis: 'development_password' serviceSecret: 'development_service_secret' twilioApiKey: 'dev_twilio_key' production: database: 'production_password' redis: 'production_password' serviceSecret: 'production_service_secret' twilioApiKey: 'prod_twilio_key' ``` -------------------------------- ### Upgrade Dart SDK in Install Dependencies Script Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/04-deploying-to-aws.md This script block installs a specified Dart SDK version if it's not already present and sets it as the default. It's intended for older Serverpod CLI versions. ```bash #!/bin/bash #### COPY THE CODE FROM HERE DART_VERSION=3.5.1 # Uncomment the following code if you have already generated the project with the older version of serverpod cli # What this code do is to remove our previous way of setting dart version in the launch template if [ -f "/etc/profile.d/script.sh" ]; then sudo rm /etc/profile.d/script.sh fi ## install specified dart version if it is not present on the machine if [ ! -d "/usr/lib/dart$DART_VERSION" ]; then wget -q https://storage.googleapis.com/dart-archive/channels/stable/release/$DART_VERSION/sdk/dartsdk-linux-x64-release.zip -P /tmp cd /tmp || exit unzip -q dartsdk-linux-x64-release.zip sudo mv dart-sdk/ /usr/lib/dart$DART_VERSION/ sudo chmod -R 755 /usr/lib/dart$DART_VERSION/ rm -rf dartsdk-linux-x64-release.zip fi ## make symlink to use this dart as default sudo ln -sf "/usr/lib/dart$DART_VERSION/bin/dart" /usr/local/bin/dart #### STOP COPYING THE CODE FROM HERE #### THE FOLLOWING SHOULD BE THE SAME AS THE PREVIOUS CODE cat > /lib/systemd/system/serverpod.service << EOF [Unit] Description=Serverpod server After=multi-user.target [Service] User=ec2-user WorkingDirectory=/home/ec2-user ExecStart=/home/ec2-user/serverpod/active/mypod_server/deploy/aws/scripts/run_serverpod Restart=always [Install] WantedBy=multi-user.target WantedBy=network-online.target EOF systemctl daemon-reload ``` -------------------------------- ### Basic Database Connection Configuration Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/06-database/01-connection.md Configure the host, port, database name, and user for your Postgres connection. Ensure the port matches your Postgres instance's listening port. ```yaml ... database: host: localhost port: 8090 name: user: postgres ... ``` -------------------------------- ### Verify Serverpod Version Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/01-upgrade-to-three.md Verify the installed version of the Serverpod CLI. ```bash serverpod version ``` -------------------------------- ### Start Server in Serverless Role Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/07-deployments/05-general.md Launch the Serverpod server with the 'serverless' role. This configuration is suitable for serverless environments where the server only handles incoming connections. ```bash $ dart bin/main.dart --role serverless ``` -------------------------------- ### Add Facebook Auth Package Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/11-authentication/04-providers/05-facebook/01-setup.md Install the necessary package for Facebook authentication in your Flutter project. ```bash flutter pub add serverpod_auth_idp_flutter_facebook ``` -------------------------------- ### Update Widget Class Names (Before) Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/08-upgrading/01-upgrade-to-three.md Example of using legacy widget class names in Serverpod 2.x. ```dart Future build(...) => Widget(name: 'page')..values = {...}; ``` -------------------------------- ### Registering Routes in Serverpod Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/01-overview.md Demonstrates how to add custom routes to the web server, including exact path matching and wildcard matching. ```dart // Exact path pod.webServer.addRoute(UserRoute(), '/api/users'); // Path with wildcard pod.webServer.addRoute(StaticRoute.directory(Directory('web')), '/static/'); ``` -------------------------------- ### Serverpod Response Types Source: https://github.com/serverpod/serverpod_docs/blob/main/versioned_docs/version-3.4.0/06-concepts/18-webserver/01-overview.md Provides examples of returning various success and error responses from a route handler. ```dart // Success responses return Response.ok(body: Body.fromString('Success')); return Response.created(body: Body.fromString('Created')); return Response.noContent(); // Error responses return Response.badRequest(body: Body.fromString('Invalid input')); return Response.unauthorized(body: Body.fromString('Not authenticated')); return Response.notFound(body: Body.fromString('Not found')); return Response.internalServerError(body: Body.fromString('Server error')); ```