@@ -82,7 +82,9 @@ app.use((req, res, next) => {
8282
8383app . use ( i18nMiddleware ) ;
8484app . use ( countRequest ) ;
85- app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
85+ app . use ( express . static ( path . join ( __dirname , 'public' ) , {
86+ maxAge : process . env . NODE_ENV === 'production' ? '1d' : 0 ,
87+ } ) ) ;
8688
8789// Sanitize error details from 500 responses in production
8890app . use ( ( req , res , next ) => {
@@ -575,50 +577,78 @@ function setupWebSocketServer(server) {
575577function setupCronJobs ( ) {
576578 // Collect stats every 5 minutes
577579 cron . schedule ( '*/5 * * * *' , async ( ) => {
578- logger . debug ( '[Cron] Collecting stats' ) ;
579- await syncService . collectAllStats ( ) ;
580-
581- // Save stats snapshot for charts
582- await statsService . saveHourlySnapshot ( ) ;
580+ try {
581+ logger . debug ( '[Cron] Collecting stats' ) ;
582+ await syncService . collectAllStats ( ) ;
583+
584+ // Save stats snapshot for charts
585+ await statsService . saveHourlySnapshot ( ) ;
586+ } catch ( error ) {
587+ logger . error ( `[Cron] Stats collection failed: ${ error . message } ` ) ;
588+ }
583589 } ) ;
584590
585591 // Health check every minute
586592 cron . schedule ( '* * * * *' , async ( ) => {
587- await syncService . healthCheck ( ) ;
593+ try {
594+ await syncService . healthCheck ( ) ;
595+ } catch ( error ) {
596+ logger . error ( `[Cron] Health check failed: ${ error . message } ` ) ;
597+ }
588598 } ) ;
589599
590600 // Save daily snapshot every hour
591601 cron . schedule ( '0 * * * *' , async ( ) => {
592- logger . debug ( '[Cron] Saving daily stats snapshot' ) ;
593- await statsService . saveDailySnapshot ( ) ;
602+ try {
603+ logger . debug ( '[Cron] Saving daily stats snapshot' ) ;
604+ await statsService . saveDailySnapshot ( ) ;
605+ } catch ( error ) {
606+ logger . error ( `[Cron] Daily snapshot failed: ${ error . message } ` ) ;
607+ }
594608 } ) ;
595609
596610 // Save monthly snapshot and cleanup at 00:05
597611 cron . schedule ( '5 0 * * *' , async ( ) => {
598- logger . info ( '[Cron] Saving monthly stats snapshot' ) ;
599- await statsService . saveMonthlySnapshot ( ) ;
600- await statsService . cleanup ( ) ;
612+ try {
613+ logger . info ( '[Cron] Saving monthly stats snapshot' ) ;
614+ await statsService . saveMonthlySnapshot ( ) ;
615+ await statsService . cleanup ( ) ;
616+ } catch ( error ) {
617+ logger . error ( `[Cron] Monthly maintenance failed: ${ error . message } ` ) ;
618+ }
601619 } ) ;
602620
603621 // Clean old logs daily at 3:00
604622 cron . schedule ( '0 3 * * *' , ( ) => {
605- logger . info ( '[Cron] Cleaning old logs' ) ;
606- cleanOldLogs ( 30 ) ;
623+ try {
624+ logger . info ( '[Cron] Cleaning old logs' ) ;
625+ cleanOldLogs ( 30 ) ;
626+ } catch ( error ) {
627+ logger . error ( `[Cron] Log cleanup failed: ${ error . message } ` ) ;
628+ }
607629 } ) ;
608630
609631 // Check for scheduled backup every hour
610632 cron . schedule ( '0 * * * *' , async ( ) => {
611- await backupService . scheduledBackup ( ) ;
633+ try {
634+ await backupService . scheduledBackup ( ) ;
635+ } catch ( error ) {
636+ logger . error ( `[Cron] Scheduled backup failed: ${ error . message } ` ) ;
637+ }
612638 } ) ;
613639
614640 // Initial health check and stats snapshot after 5 seconds
615641 setTimeout ( async ( ) => {
616- logger . info ( '[Startup] Checking nodes status' ) ;
617- await syncService . healthCheck ( ) ;
618-
619- // Initial stats snapshot
620- await statsService . saveHourlySnapshot ( ) ;
621- logger . info ( '[Startup] Initial stats snapshot saved' ) ;
642+ try {
643+ logger . info ( '[Startup] Checking nodes status' ) ;
644+ await syncService . healthCheck ( ) ;
645+
646+ // Initial stats snapshot
647+ await statsService . saveHourlySnapshot ( ) ;
648+ logger . info ( '[Startup] Initial stats snapshot saved' ) ;
649+ } catch ( error ) {
650+ logger . error ( `[Startup] Initial checks failed: ${ error . message } ` ) ;
651+ }
622652 } , 5000 ) ;
623653}
624654
0 commit comments