cleaned up index

This commit is contained in:
Boki 2025-06-10 21:06:01 -04:00
parent b49bea818b
commit df611a3ce3

View file

@ -19,8 +19,8 @@ loadEnvVariables();
const app = new Hono(); const app = new Hono();
const logger = getLogger('data-service'); const logger = getLogger('data-service');
const PORT = parseInt(process.env.DATA_SERVICE_PORT || '3002'); const PORT = parseInt(process.env.DATA_SERVICE_PORT || '3002');
let server: any = null;
// Register all routes // Register all routes
app.route('', healthRoutes); app.route('', healthRoutes);
@ -47,27 +47,18 @@ async function initializeServices() {
} }
// Start server // Start server
let server: any = null;
async function startServer() { async function startServer() {
await initializeServices(); await initializeServices();
// Start the HTTP server using Bun's native serve // Start the HTTP server using Bun's native serve
server = Bun.serve({ server = Bun.serve({
port: PORT, port: PORT,
fetch: app.fetch, fetch: app.fetch,
development: process.env.NODE_ENV === 'development', development: process.env.NODE_ENV === 'development',
}); });
logger.info(`Data Service started on port ${PORT}`); logger.info(`Data Service started on port ${PORT}`);
// Register shutdown callbacks
setupShutdownHandlers();
} }
// Setup shutdown handlers using the shutdown library // Setup shutdown handling
function setupShutdownHandlers() {
// Set shutdown timeout to 15 seconds
setShutdownTimeout(15000); setShutdownTimeout(15000);
// Register cleanup for HTTP server // Register cleanup for HTTP server
@ -84,10 +75,9 @@ function setupShutdownHandlers() {
await queueManager.shutdown(); await queueManager.shutdown();
}); });
logger.info('Shutdown handlers registered');
}
startServer().catch(error => { startServer().catch(error => {
logger.error('Failed to start server', { error }); logger.error('Failed to start server', { error });
process.exit(1); process.exit(1);
}); });
logger.info('Shutdown handlers registered');