Add database connection test API

This commit is contained in:
Randall Stillwell 2025-07-23 09:41:38 -05:00
parent 373f103810
commit dc419f681b

32
pages/api/test-db.js Normal file
View file

@ -0,0 +1,32 @@
import { sql } from '@vercel/postgres';
export default async function handler(req, res) {
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
// Handle preflight requests
if (req.method === 'OPTIONS') {
res.status(200).end();
return;
}
try {
// Test database connection
const result = await sql`SELECT NOW() as current_time, version() as postgres_version`;
res.status(200).json({
success: true,
message: 'Database connection successful!',
data: result.rows[0],
timestamp: new Date().toISOString()
});
} catch (error) {
console.error('Database test error:', error);
res.status(500).json({
error: 'Database connection failed',
details: error.message
});
}
}