Files
TeleUploader/src/index.ts
T

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import { serve } from 'bun';
2026-05-18 07:27:06 +07:00
import { startBot } from './bot';
import { config } from './env';
import { handleFileInfo, handleFileRedirect } from './routes/files';
2026-05-18 07:27:06 +07:00
import { handleHealth } from './routes/health';
import { handleUpload } from './routes/upload';
import logger from './utils/logger';
2026-05-18 07:27:06 +07:00
import { cleanupRateLimitCache } from './utils/rateLimit';
const server = serve({
port: config.port,
routes: {
'/api/upload': {
POST: handleUpload,
},
'/f/:public_id': {
GET: handleFileRedirect,
},
'/file/:public_id/info': {
GET: handleFileInfo,
},
'/health': {
GET: handleHealth,
},
},
});
const bot = await startBot();
logger.info('Server started', { port: config.port, url: config.baseUrl });
2026-05-18 07:27:06 +07:00
const gracefulShutdown = async (signal: string): Promise<void> => {
logger.info('Graceful shutdown signal received', { signal });
logger.info('Closing HTTP server');
server.stop();
logger.info('Stopping Telegram bot');
2026-05-18 07:27:06 +07:00
bot.stop(signal);
logger.info('Server shutdown complete');
process.exit(0);
};
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
setInterval(cleanupRateLimitCache, 60000);
logger.info('Application running successfully');