Bluesky app fork with some witchin' additions 馃挮
at main 1.6 kB view raw
1import {Database, envToCfg, httpLogger, LinkService, readEnv} from './index.js' 2 3async function main() { 4 try { 5 httpLogger.info('Starting blink service') 6 7 const env = readEnv() 8 const cfg = envToCfg(env) 9 10 httpLogger.info( 11 { 12 port: cfg.service.port, 13 safelinkEnabled: cfg.service.safelinkEnabled, 14 hasDbUrl: !!cfg.db.url, 15 hasDbMigrationUrl: !!cfg.db.migrationUrl, 16 }, 17 'Configuration loaded', 18 ) 19 20 if (cfg.db.migrationUrl) { 21 httpLogger.info('Running database migrations') 22 const migrateDb = Database.postgres({ 23 url: cfg.db.migrationUrl, 24 schema: cfg.db.schema, 25 }) 26 await migrateDb.migrateToLatestOrThrow() 27 await migrateDb.close() 28 httpLogger.info('Database migrations completed') 29 } 30 31 httpLogger.info('Creating LinkService') 32 const link = await LinkService.create(cfg) 33 34 if (link.ctx.cfg.service.safelinkEnabled) { 35 httpLogger.info('Starting Safelink client') 36 link.ctx.safelinkClient.runFetchEvents() 37 } 38 39 await link.start() 40 httpLogger.info('Link service is running') 41 42 process.on('SIGTERM', async () => { 43 httpLogger.info('Link service is stopping') 44 await link.destroy() 45 httpLogger.info('Link service is stopped') 46 }) 47 } catch (error) { 48 httpLogger.error( 49 { 50 error: String(error), 51 stack: error instanceof Error ? error.stack : undefined, 52 }, 53 'Failed to start blink service', 54 ) 55 process.exit(1) 56 } 57} 58 59main().catch(error => { 60 console.error('Unhandled startup error:', error) 61 process.exit(1) 62})