53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { testMongoConnection } from '@/lib/mongodb'
|
|
|
|
export async function GET() {
|
|
try {
|
|
console.log('🚀 Running startup connection tests...')
|
|
|
|
const mongoStatus = await testMongoConnection()
|
|
|
|
// Test Redis connection (basic check)
|
|
let redisStatus = false
|
|
try {
|
|
// Import redis client
|
|
const { redisClient } = await import('@/lib/redis')
|
|
await redisClient.ping()
|
|
console.log('✅ Redis connection test successful')
|
|
redisStatus = true
|
|
} catch (error) {
|
|
console.error('❌ Redis connection test failed:', error)
|
|
console.error('Redis is optional but recommended for session storage')
|
|
}
|
|
|
|
const overallStatus = mongoStatus // Redis is optional, so we only require MongoDB
|
|
|
|
if (overallStatus) {
|
|
console.log('🎉 All critical services are connected and ready!')
|
|
} else {
|
|
console.log('⚠️ Some services failed connection tests')
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: overallStatus,
|
|
services: {
|
|
mongodb: mongoStatus,
|
|
redis: redisStatus,
|
|
},
|
|
message: overallStatus
|
|
? 'All critical services connected successfully'
|
|
: 'Some services failed connection tests - check logs',
|
|
})
|
|
} catch (error) {
|
|
console.error('❌ Startup test failed:', error)
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'Startup test failed',
|
|
message: 'Check server logs for details',
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|