Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place
1import app from './server'; 2import { serve } from '@hono/node-server'; 3import { FirehoseWorker } from './lib/firehose'; 4import { logger } from './lib/observability'; 5import { mkdirSync, existsSync } from 'fs'; 6 7const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3001; 8const CACHE_DIR = './cache/sites'; 9 10// Ensure cache directory exists 11if (!existsSync(CACHE_DIR)) { 12 mkdirSync(CACHE_DIR, { recursive: true }); 13 console.log('Created cache directory:', CACHE_DIR); 14} 15 16// Start firehose worker with observability logger 17const firehose = new FirehoseWorker((msg, data) => { 18 logger.info(msg, data); 19}); 20 21firehose.start(); 22 23// Add health check endpoint 24app.get('/health', (c) => { 25 const firehoseHealth = firehose.getHealth(); 26 return c.json({ 27 status: 'ok', 28 firehose: firehoseHealth, 29 }); 30}); 31 32// Start HTTP server with Node.js adapter 33const server = serve({ 34 fetch: app.fetch, 35 port: PORT, 36}); 37 38console.log(` 39Wisp Hosting Service 40 41Server: http://localhost:${PORT} 42Health: http://localhost:${PORT}/health 43Cache: ${CACHE_DIR} 44Firehose: Connected to Firehose 45`); 46 47// Graceful shutdown 48process.on('SIGINT', async () => { 49 console.log('\n🛑 Shutting down...'); 50 firehose.stop(); 51 server.close(); 52 process.exit(0); 53}); 54 55process.on('SIGTERM', async () => { 56 console.log('\n🛑 Shutting down...'); 57 firehose.stop(); 58 server.close(); 59 process.exit(0); 60});