@@ -20,6 +20,8 @@ import securityRoutes from './routes/security';
2020import { updateActivity } from './middleware/authMiddleware' ;
2121import EmailService from './services/EmailService' ;
2222import PM2LogService from './services/PM2LogService' ;
23+ import { discordWebhookService } from './services/DiscordWebhookService' ;
24+ import { serverProvisioningMonitor } from './services/ServerProvisioningMonitor' ;
2325
2426// Load environment variables
2527dotenv . config ( ) ;
@@ -136,6 +138,12 @@ app.use('/api/system', systemRoutes);
136138app . use ( '/api/audit' , securityRoutes ) ;
137139app . use ( '/api/security' , securityRoutes ) ;
138140
141+ // Test routes (only in development)
142+ if ( NODE_ENV === 'development' ) {
143+ const testNotificationRoutes = require ( './routes/test-notifications' ) . default ;
144+ app . use ( '/api/test-notifications' , testNotificationRoutes ) ;
145+ }
146+
139147// Health check endpoint
140148app . get ( '/api/health' , ( req , res ) => {
141149 res . json ( {
@@ -161,6 +169,13 @@ if (require('fs').existsSync(clientDistPath)) {
161169app . use ( ( err : any , req : express . Request , res : express . Response , next : express . NextFunction ) => {
162170 console . error ( 'Global error handler:' , err ) ;
163171
172+ // Send Discord notification for errors
173+ if ( discordWebhookService . isConfigured ( ) ) {
174+ discordWebhookService . sendPanelError ( err , req ) . catch ( error => {
175+ console . error ( 'Failed to send Discord notification:' , error ) ;
176+ } ) ;
177+ }
178+
164179 res . status ( err . status || 500 ) . json ( {
165180 success : false ,
166181 error : NODE_ENV === 'production' ? 'Internal server error' : err . message ,
@@ -213,6 +228,10 @@ async function startServer() {
213228
214229 // Initialize PM2 log streaming based on configuration
215230 initializePM2Logging ( ) ;
231+
232+ // Start server provisioning monitor
233+ serverProvisioningMonitor . start ( ) ;
234+ console . log ( `🔍 Server provisioning monitor started` ) ;
216235 } ) ;
217236 } catch ( error ) {
218237 console . error ( 'Failed to start server:' , error ) ;
@@ -224,6 +243,7 @@ async function startServer() {
224243process . on ( 'SIGTERM' , async ( ) => {
225244 console . log ( '🛑 SIGTERM received, shutting down gracefully' ) ;
226245 PM2LogService . stopStreaming ( ) ;
246+ serverProvisioningMonitor . stop ( ) ;
227247 io . close ( ) ;
228248 await mongoose . connection . close ( ) ;
229249 process . exit ( 0 ) ;
@@ -232,6 +252,7 @@ process.on('SIGTERM', async () => {
232252process . on ( 'SIGINT' , async ( ) => {
233253 console . log ( '🛑 SIGINT received, shutting down gracefully' ) ;
234254 PM2LogService . stopStreaming ( ) ;
255+ serverProvisioningMonitor . stop ( ) ;
235256 io . close ( ) ;
236257 await mongoose . connection . close ( ) ;
237258 process . exit ( 0 ) ;
0 commit comments