feat(todo): the server on halkyon_base

Todo's server includes halkyon_base (ADR 0014), configured for Todo:
its basics say it serves `todo`, sign-in mails name Halkyon Todo, the
source is this repository, minimumAppBuild 1. Authentication through
the module (anonymous, GitHub, email codes, server-side sessions) in
place of the scaffold's email-and-password provider; the module's
pruning scheduled once however often the server starts. The scaffold's
greeting, its Flutter web hosting, cloud storage and Docker files go;
session logs are never persisted. Todo was never deployed, so its
migrations start again with one initial migration. The root's lints
apply, with the four constructor rules off as on Learn's server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-19 21:56:12 +02:00
commit 28dd3ea65a
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -1,109 +1,25 @@
import 'dart:io';
import 'package:halkyon_base_server/base.dart';
import 'package:halkyon_todo_server/src/generated/serverpod.dart';
import 'package:halkyon_todo_server/src/pruning.dart';
import 'package:halkyon_todo_server/src/todo_base.dart';
import 'package:serverpod_auth_idp_server/core.dart';
import 'package:serverpod_auth_idp_server/providers/email.dart';
import 'package:serverpod_cloud_storage/serverpod_cloud_storage.dart';
import 'src/cache_busting.dart';
import 'src/generated/serverpod.dart';
import 'src/web/routes/app_config_route.dart';
/// The starting point of the Serverpod server.
void run(List<String> args) async {
// Initialize Serverpod. The generated Serverpod class is already connected
// with your project's generated code.
/// The starting point of Halkyon Todo's server.
Future<void> run(List<String> args) async {
// The generated Serverpod is already connected with the generated code.
final pod = Serverpod(args);
// Initialize authentication services for the server.
// Token managers will be used to validate and issue authentication keys,
// and the identity providers will be the authentication options available for users.
// What every Halkyon server has (ADR 0014): sign-in, the account and its
// deletion, the pruning, the instance's basics, set up for Todo.
HalkyonBase.configure(pod, todoBase());
// Token managers validate and issue authentication keys; identity
// providers are the ways people can sign in (halkyon_base's
// auth_config.dart).
pod.initializeAuthServices(
tokenManagerBuilders: [
// Server-side sessions: every request looks its session up in the
// database, so signing out or deleting an account takes effect at once.
// A session unused for 90 days expires; one in use never does.
ServerSideSessionsConfigFromPasswords(
defaultSessionInactivityTimeout: const Duration(days: 90),
),
],
identityProviderBuilders: [
// Configure the email identity provider for email/password authentication.
// The default setup works with Serverpod Cloud without configuration. In
// development the verification codes are logged to the console, and in
// staging and production they are sent through the Serverpod Cloud email
// service. If you want to use a custom provider for sending emails, use
// `EmailIdpConfigFromPasswords`.
ServerpodCloudEmailIdpConfig(
appDisplayName: 'halkyon_todo',
),
],
tokenManagerBuilders: tokenManagerBuilders,
identityProviderBuilders: identityProviderBuilders(pod),
);
// Serve all files in the web/static relative directory under /web.
// These are used by the default web page.
pod.webServer.addRoute(
StaticRoute.withCacheBusting(cacheBustingConfig),
cacheBustingConfig.mountPrefix,
);
// Setup the app config route.
// We build this configuration based on the servers api url and serve it to
// the flutter app.
pod.webServer.addRoute(
AppConfigRoute(apiConfig: pod.config.apiServer),
'/assets/assets/config.json',
);
// Checks if the flutter web app has been built and serves it if it has.
final appDir = Directory(Uri(path: 'web/app').toFilePath());
if (appDir.existsSync()) {
// Serve the flutter web app under /.
pod.webServer.addRoute(
FlutterRoute(
appDir,
// If building the Flutter app with WASM, set the below parameter to
// true and add the --wasm flag to the flutter build command.
enableWasmHeaders: false,
),
'/',
);
} else {
// If the flutter web app has not been built, serve the build app page.
final defaultRoute = StaticRoute.file(
File(
Uri(path: 'web/pages/build_flutter_app.html').toFilePath(),
),
);
pod.webServer.addMiddleware(
FallbackMiddleware(
fallback: defaultRoute,
on: (response) => response.statusCode == 404,
).call,
'/',
);
pod.webServer.addRoute(
defaultRoute,
'/**',
);
}
// Configure cloud storage.
// This setup works with Serverpod Cloud without extra configuration.
// If you want to use a custom provider for cloud storage, replace these
// with your preferred provider.
pod.addCloudStorage(
await ServerpodCloudProvider.private(
fallback: () => DatabaseCloudStorage('private'),
),
);
pod.addCloudStorage(
await ServerpodCloudProvider.public(
fallback: () => DatabaseCloudStorage('public'),
),
);
// Start the server.
await pod.start();
await schedulePruning(pod);
}