/** * Web CAD Backend – Entry Point */ import { createServer } from './server.js'; import { SqliteAdapter } from './database/SqliteAdapter.js'; import { initYjsPersistence, closeYjsPersistence } from './websocket/yjsServer.js'; const PORT = parseInt(process.env.PORT || '3001', 10); const HOST = process.env.HOST || '0.0.0.0'; const DB_PATH = process.env.DB_PATH || '/data/web-cad.db'; async function main() { const db = new SqliteAdapter(DB_PATH); await db.init(); await initYjsPersistence(); const fastify = await createServer({ port: PORT, host: HOST, db }); try { await fastify.listen({ port: PORT, host: HOST }); console.log(`Web CAD Backend running on http://${HOST}:${PORT}`); } catch (err) { fastify.log.error(err); process.exit(1); } // Graceful shutdown const shutdown = async (signal: string) => { console.log(`Received ${signal}, shutting down gracefully...`); await fastify.close(); await closeYjsPersistence(); db.close(); process.exit(0); }; process.on('SIGTERM', () => shutdown('SIGTERM')); process.on('SIGINT', () => shutdown('SIGINT')); } main();