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