Merge branch '4-add-broadcaster' into 5-add-http-and-sse

This commit is contained in:
2026-09-02 09:58:51 +00:00
13 changed files with 404 additions and 36 deletions
+17 -2
View File
@@ -1,10 +1,12 @@
import { Config } from './services/config.ts';
import { Database, MigrationService } from './services/storage/index.ts';
import { AuthSecp256k1 } from './auth/auth.ts';
import { Broadcaster } from './services/broadcaster.ts';
import { ApplicationRouter } from './services/router.ts';
import { HttpTransportRouter } from './services/transport/http-transport.ts';
import { ServerHost } from './services/server-host.ts';
import { Logger } from './utils/logger.ts';
import type { RouteModule } from './routes/types.ts';
/** Application composition root. */
export class App {
@@ -21,14 +23,17 @@ export class App {
const migrations = new MigrationService(database, debug);
await migrations.migrateToLatest();
// Create an Auth instance that can be passed in for signature validation
const auth = await AuthSecp256k1.create({ database }, { timestampWindowMs: config.auth.timestampWindowMs });
// Domain services are shared across all transports and route modules.
const broadcaster = new Broadcaster(debug);
const routes = [];
const routes: RouteModule[] = [];
// Route loading is an explicit startup phase, not first-request work.
// ApplicationRouter.create validates every path and rejects duplicates
// before any client can connect.
const router = await ApplicationRouter.create(routes);
const router = await ApplicationRouter.create({ auth }, routes);
const http = new HttpTransportRouter(router, debug);
const host = new ServerHost(config, debug, [ http ]);
@@ -59,6 +64,16 @@ export class App {
})();
await this.stopPromise;
}
startUniqueRequestCleanup(cleanupIntervalMs: number, timestampWindowMs: number): void {
// Every 10 seconds, we will cleanup the requests table
setInterval(async () => {
await this.database.db
.deleteFrom('authed_requests')
.where('timestamp', '<', Date.now() - timestampWindowMs)
.execute();
}, cleanupIntervalMs);
}
}
const app = await App.create();