|
|
|
@ -8,6 +8,19 @@ dotenv.config();
|
|
|
|
|
// Get port from environment or default to 3000
|
|
|
|
|
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3000;
|
|
|
|
|
|
|
|
|
|
// Enhanced error logging
|
|
|
|
|
function logError(error: unknown) {
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
console.error('Error:', error.message);
|
|
|
|
|
console.error('Stack:', error.stack);
|
|
|
|
|
if (error.cause) {
|
|
|
|
|
console.error('Caused by:', error.cause);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unknown error:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start the bot and server
|
|
|
|
|
async function main() {
|
|
|
|
|
try {
|
|
|
|
@ -18,21 +31,49 @@ async function main() {
|
|
|
|
|
console.log('Starting server...');
|
|
|
|
|
startServer(PORT);
|
|
|
|
|
console.log(`Server running on port ${PORT}`);
|
|
|
|
|
|
|
|
|
|
// Keep process alive
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
// Just keep the event loop running
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error starting application:', error);
|
|
|
|
|
console.error('\n=== APPLICATION FAILED TO START ===');
|
|
|
|
|
logError(error);
|
|
|
|
|
console.error('===============================');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle process termination
|
|
|
|
|
process.on('SIGINT', () => {
|
|
|
|
|
console.log('Shutting down gracefully...');
|
|
|
|
|
console.log('\nShutting down gracefully...');
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
process.on('SIGTERM', () => {
|
|
|
|
|
console.log('Shutting down gracefully...');
|
|
|
|
|
console.log('\nShutting down gracefully...');
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
main();
|
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
|
|
console.error('\n=== UNCAUGHT EXCEPTION ===');
|
|
|
|
|
logError(error);
|
|
|
|
|
console.error('=========================');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
|
|
|
console.error('\n=== UNHANDLED REJECTION ===');
|
|
|
|
|
console.error('Promise:', promise);
|
|
|
|
|
console.error('Reason:', reason);
|
|
|
|
|
console.error('=========================');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
|
console.error('\n=== MAIN FUNCTION FAILED ===');
|
|
|
|
|
logError(error);
|
|
|
|
|
console.error('=========================');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|