faster smaller
This commit is contained in:
@@ -276,8 +276,8 @@ app.get('/health', (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
// Error handler
|
||||
app.use((_err: Error, _req: Request, res: Response) => {
|
||||
console.error(_err.stack);
|
||||
app.use((err: Error, _req: Request, res: Response, _next: any) => {
|
||||
console.error(err.stack);
|
||||
res.status(500).json({ error: 'Something went wrong!' });
|
||||
});
|
||||
|
||||
@@ -316,7 +316,7 @@ app.listen(port, () => {
|
||||
const botToken = process.env.TELEGRAM_BOT_TOKEN;
|
||||
const webAppUrl = process.env.WEB_APP_URL || `http://localhost:${port}`;
|
||||
|
||||
if (botToken && botToken.length > 10) {
|
||||
if (botToken && botToken.length > 10 && botToken !== 'your_telegram_bot_token_here') {
|
||||
try {
|
||||
const botInstance = new QuixoticBot(botToken, webAppUrl);
|
||||
// Store bot instance globally for API access
|
||||
@@ -324,10 +324,31 @@ if (botToken && botToken.length > 10) {
|
||||
console.log('🤖 Telegram bot started and stored globally');
|
||||
} catch (error: any) {
|
||||
console.error('❌ Bot initialization failed:', error.message);
|
||||
console.warn('⚠️ Bot disabled due to error');
|
||||
console.warn('⚠️ Bot disabled due to error');
|
||||
console.warn('⚠️ Telegram integration will not be available');
|
||||
// Don't crash the server, continue without bot
|
||||
}
|
||||
} else {
|
||||
console.warn('⚠️ TELEGRAM_BOT_TOKEN not found or invalid - bot will not start');
|
||||
console.warn('⚠️ TELEGRAM_BOT_TOKEN not configured properly');
|
||||
console.warn('⚠️ Bot will not start - only web interface will be available');
|
||||
console.warn('ℹ️ To enable Telegram bot, set a valid TELEGRAM_BOT_TOKEN');
|
||||
}
|
||||
|
||||
// Handle unhandled promise rejections
|
||||
process.on('unhandledRejection', (reason: any, promise: Promise<any>) => {
|
||||
console.error('🚨 Unhandled Rejection at:', promise);
|
||||
console.error('Reason:', reason);
|
||||
|
||||
// Log but don't crash the server
|
||||
if (reason?.code === 'ETELEGRAM') {
|
||||
console.warn('⚠️ Telegram API error - continuing operation');
|
||||
}
|
||||
});
|
||||
|
||||
// Handle uncaught exceptions
|
||||
process.on('uncaughtException', (error: Error) => {
|
||||
console.error('🚨 Uncaught Exception:', error);
|
||||
// Log but try to continue
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user