A social knowledge tool for researchers built on ATProto
at development 1.3 kB view raw
1import { IProcess } from '../../domain/IProcess'; 2import { createExpressApp } from '../http/app'; 3import { DatabaseFactory } from '../database/DatabaseFactory'; 4import { EnvironmentConfigService } from '../config/EnvironmentConfigService'; 5 6export class AppProcess implements IProcess { 7 constructor(private configService: EnvironmentConfigService) {} 8 9 async start(): Promise<void> { 10 // Get configuration 11 const config = this.configService.get(); 12 13 const useMockRepos = process.env.USE_MOCK_REPOS === 'true'; 14 if (!useMockRepos) { 15 // Create database connection with config 16 const db = DatabaseFactory.createConnection( 17 this.configService.getDatabaseConfig(), 18 ); 19 20 // Run migrations 21 try { 22 await DatabaseFactory.runMigrations(db); 23 console.log('Database migrations completed successfully'); 24 } catch (error) { 25 console.error('Error running database migrations:', error); 26 process.exit(1); 27 } 28 } 29 30 // Create and start Express app with config 31 const app = createExpressApp(this.configService); 32 const PORT = config.server.port; 33 const HOST = config.server.host; 34 35 app.listen(PORT, HOST, () => { 36 console.log( 37 `Server running on http://${HOST}:${PORT} in ${config.environment} environment`, 38 ); 39 }); 40 } 41}