Scratch space for learning atproto app development
1import { once } from 'node:events' 2 3import { createAppContext } from '#/context' 4import { env } from '#/env' 5import { startServer } from '#/lib/http' 6import { run } from '#/lib/process' 7import { createRouter } from '#/routes' 8 9run(async (killSignal) => { 10 // Create the application context 11 const ctx = await createAppContext() 12 13 // Create the HTTP router 14 const router = createRouter(ctx) 15 16 // Start the HTTP server 17 const { terminate } = await startServer(router, { port: env.PORT }) 18 19 const url = env.PUBLIC_URL || `http://localhost:${env.PORT}` 20 ctx.logger.info(`Server (${env.NODE_ENV}) running at ${url}`) 21 22 // Subscribe to events on the firehose 23 ctx.ingester.start() 24 25 // Wait for a termination signal 26 if (!killSignal.aborted) await once(killSignal, 'abort') 27 ctx.logger.info(`Signal received, shutting down...`) 28 29 // Gracefully shutdown the http server 30 await terminate() 31 32 // Gracefully shutdown the application context 33 await ctx.destroy() 34})