Merge branch '5-add-http-and-sse' into 6-add-websocket-transport

This commit is contained in:
2026-09-02 09:59:28 +00:00
13 changed files with 402 additions and 35 deletions
+15 -1
View File
@@ -1,5 +1,6 @@
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';
@@ -23,6 +24,9 @@ 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 = [
@@ -34,7 +38,7 @@ export class App {
// 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);
// Both transports share one ApplicationRouter. Routes use the shared
// Broadcaster directly, while HTTP and WebSocket remain protocol adapters.
@@ -69,6 +73,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();