Merge branch '3.5-add-auth' into 4-add-broadcaster
This commit is contained in:
+17
-2
@@ -1,8 +1,10 @@
|
||||
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 { Logger } from './utils/logger.ts';
|
||||
import type { RouteModule } from './routes/types.ts';
|
||||
|
||||
/** Application composition root. */
|
||||
export class App {
|
||||
@@ -19,14 +21,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);
|
||||
|
||||
return new App(database, broadcaster, router);
|
||||
}
|
||||
@@ -48,6 +53,16 @@ export class App {
|
||||
this.stopPromise ??= this.database.destroy();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user