initial commit
This commit is contained in:
48
lib/startup.ts
Normal file
48
lib/startup.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Server-side startup checks - runs when Next.js server starts
|
||||
let startupComplete = false
|
||||
|
||||
export async function runStartupChecks() {
|
||||
if (startupComplete) return // Only run once
|
||||
|
||||
console.log('\n🚀 NextJS Boilerplate - Running startup checks...')
|
||||
console.log('='.repeat(60))
|
||||
|
||||
try {
|
||||
// Test MongoDB connection
|
||||
const { testMongoConnection } = await import('./mongodb')
|
||||
const mongoStatus = await testMongoConnection()
|
||||
|
||||
// Test Redis connection (optional)
|
||||
let redisStatus = false
|
||||
try {
|
||||
const { connectRedis } = await import('./redis')
|
||||
const redisClient = await connectRedis()
|
||||
await redisClient.ping()
|
||||
console.log('✅ Redis connection successful')
|
||||
redisStatus = true
|
||||
} catch (error) {
|
||||
console.log('⚠️ Redis connection failed (optional service)')
|
||||
console.log(' → Redis is used for session storage but app will work without it')
|
||||
}
|
||||
|
||||
console.log('='.repeat(60))
|
||||
|
||||
if (mongoStatus) {
|
||||
console.log('🎉 All critical services connected - App ready!')
|
||||
console.log(` → Local: http://localhost:${process.env.PORT || 3006}`)
|
||||
console.log(` → Database: Connected to MongoDB`)
|
||||
console.log(` → Sessions: ${redisStatus ? 'Redis enabled' : 'Fallback to memory'}`)
|
||||
} else {
|
||||
console.log('❌ Critical services failed - App may not work properly')
|
||||
console.log(' → Check MongoDB connection and try again')
|
||||
}
|
||||
|
||||
console.log('='.repeat(60))
|
||||
startupComplete = true
|
||||
} catch (error) {
|
||||
console.error('❌ Startup checks failed:', error)
|
||||
console.log('='.repeat(60))
|
||||
}
|
||||
}
|
||||
|
||||
// Export for explicit use in layout
|
||||
Reference in New Issue
Block a user