widget news fetch 9
This commit is contained in:
parent
c558fe79e4
commit
61e8872cd1
@ -66,16 +66,20 @@ const MOCK_NEWS = [
|
||||
];
|
||||
|
||||
export async function GET() {
|
||||
// For now, return mock data while database setup is in progress
|
||||
return NextResponse.json({ news: MOCK_NEWS });
|
||||
|
||||
/* Commented out database code until properly configured
|
||||
try {
|
||||
console.log('Attempting database connection with config:', {
|
||||
user: dbConfig.user,
|
||||
host: dbConfig.host,
|
||||
database: dbConfig.database,
|
||||
// Excluding password for security
|
||||
});
|
||||
|
||||
// Connect to the database
|
||||
const client = await pool.connect();
|
||||
console.log('Successfully connected to database');
|
||||
|
||||
try {
|
||||
console.log('Executing news query...');
|
||||
// Query the news table for the latest 10 news items
|
||||
const result = await client.query(`
|
||||
SELECT
|
||||
@ -95,6 +99,8 @@ export async function GET() {
|
||||
LIMIT 10
|
||||
`);
|
||||
|
||||
console.log(`Found ${result.rows.length} news items`);
|
||||
|
||||
// Format the response
|
||||
const news = result.rows.map(row => ({
|
||||
id: row.id,
|
||||
@ -116,13 +122,16 @@ export async function GET() {
|
||||
} finally {
|
||||
// Release the client back to the pool
|
||||
client.release();
|
||||
console.log('Database client released');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Database error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch news' },
|
||||
{
|
||||
error: 'Failed to fetch news',
|
||||
details: error instanceof Error ? error.message : String(error)
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user