Add HTTP, SSE, and server hosting
This commit is contained in:
+17
-5
@@ -2,6 +2,8 @@ import { Config } from './services/config.ts';
|
||||
import { Database, MigrationService } from './services/storage/index.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';
|
||||
|
||||
/** Application composition root. */
|
||||
@@ -28,22 +30,32 @@ export class App {
|
||||
// before any client can connect.
|
||||
const router = await ApplicationRouter.create(routes);
|
||||
|
||||
return new App(database, broadcaster, router);
|
||||
const http = new HttpTransportRouter(router, debug);
|
||||
const host = new ServerHost(config, debug, [http]);
|
||||
|
||||
return new App(host, database);
|
||||
}
|
||||
|
||||
private stopPromise: Promise<void> | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly host: ServerHost,
|
||||
private readonly database: Database,
|
||||
private readonly broadcaster: Broadcaster,
|
||||
private readonly router: ApplicationRouter,
|
||||
) {}
|
||||
|
||||
async start(): Promise<void> {}
|
||||
async start(): Promise<void> {
|
||||
await this.host.start();
|
||||
}
|
||||
|
||||
/** Stop transports before releasing the database they may still use. */
|
||||
async stop(): Promise<void> {
|
||||
this.stopPromise ??= this.database.destroy();
|
||||
this.stopPromise ??= (async (): Promise<void> => {
|
||||
try {
|
||||
await this.host.stop();
|
||||
} finally {
|
||||
await this.database.destroy();
|
||||
}
|
||||
})();
|
||||
await this.stopPromise;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user