From 61e8872cd1bfdc78a7cd5206abdec487b9b3f2f3 Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 23:14:00 +0200 Subject: [PATCH] widget news fetch 9 --- app/api/news/route.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/api/news/route.ts b/app/api/news/route.ts index f2c10745..43188657 100644 --- a/app/api/news/route.ts +++ b/app/api/news/route.ts @@ -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 } ); } - */ } \ No newline at end of file