-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-prod.js
More file actions
62 lines (49 loc) · 1.75 KB
/
start-prod.js
File metadata and controls
62 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
/**
* Atlas Backend Production Server
*
* Production-optimized startup script with proper error handling,
* process management, and graceful shutdown.
*/
require('dotenv').config();
// Ensure production environment
process.env.NODE_ENV = 'production';
const { default: atlasApp } = require('./dist/backend/app');
console.log('🚀 Starting Atlas Backend in PRODUCTION mode...');
console.log('⚡ Optimized for performance and stability');
// Production error handling
process.on('uncaughtException', (error) => {
console.error('💥 CRITICAL: Uncaught Exception:', error.message);
console.error('🔍 Stack trace logged separately for debugging');
// Log full stack trace to error log in production
if (process.env.LOG_LEVEL === 'debug') {
console.error(error.stack);
}
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('🚫 CRITICAL: Unhandled Promise Rejection:', reason);
console.error('📍 Promise:', promise);
process.exit(1);
});
// Handle process signals for graceful shutdown
const gracefulShutdown = async (signal) => {
console.log(`\n🛑 Received ${signal} in production, initiating graceful shutdown...`);
try {
await atlasApp.stop();
console.log('✅ Atlas Backend shut down gracefully');
process.exit(0);
} catch (error) {
console.error('❌ Error during graceful shutdown:', error.message);
process.exit(1);
}
};
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
// Start the application
atlasApp.start().then(() => {
console.log('🎉 Atlas Backend successfully started in production!');
}).catch((error) => {
console.error('❌ FATAL: Failed to start Atlas Backend:', error.message);
process.exit(1);
});