Add require() postgres test and update Vercel config
This commit is contained in:
parent
dda057c1d6
commit
a528676f37
2 changed files with 39 additions and 0 deletions
38
pages/api/test-postgres-require.js
Normal file
38
pages/api/test-postgres-require.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
}
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).json({ error: 'Method not allowed' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Use require instead of import
|
||||
const { sql } = require('@vercel/postgres');
|
||||
|
||||
// Test database connection
|
||||
const result = await sql`SELECT NOW() as current_time, version() as postgres_version`;
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'PostgreSQL connection successful!',
|
||||
data: result.rows[0],
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('❌ PostgreSQL connection error:', error);
|
||||
return res.status(500).json({
|
||||
error: 'PostgreSQL connection failed',
|
||||
details: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
"framework": "nextjs",
|
||||
"buildCommand": "npm run build",
|
||||
"outputDirectory": ".next",
|
||||
"installCommand": "npm install",
|
||||
"headers": [
|
||||
{
|
||||
"source": "/static/(.*)",
|
||||
|
|
|
|||
Loading…
Reference in a new issue