correction news widget v6
This commit is contained in:
parent
220ad5fdb5
commit
4de568a1d8
12
.env
12
.env
@ -47,12 +47,10 @@ ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
|
|||||||
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
||||||
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
||||||
LEANTIME_API_URL=https://agilite.slm-lab.net
|
LEANTIME_API_URL=https://agilite.slm-lab.net
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
NEWSDB_URL=postgresql://alma:Sict33711###@cube.governance-labs.com/rivacube
|
# Database Configuration
|
||||||
=======
|
|
||||||
DB_USER=alma
|
|
||||||
DB_PASSWORD=Sict33711###
|
|
||||||
DB_NAME=rivacube
|
|
||||||
DB_HOST=cube.governance-labs.com
|
DB_HOST=cube.governance-labs.com
|
||||||
>>>>>>> 1abc8e9fe8b5d9382da1c53238741114288da34c
|
DB_PORT=5432
|
||||||
|
DB_USER=alma
|
||||||
|
DB_PASSWORD=Sict33711
|
||||||
|
DB_NAME=rivacube
|
||||||
|
|||||||
@ -1,30 +1,72 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
|
|
||||||
|
// Get database configuration from environment variables
|
||||||
|
const DB_HOST = process.env.DB_HOST || 'cube.governance-labs.com';
|
||||||
|
const DB_PORT = process.env.DB_PORT || '5432';
|
||||||
|
const DB_USER = process.env.DB_USER || 'alma';
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD;
|
||||||
|
const DB_NAME = process.env.DB_NAME || 'rivacube';
|
||||||
|
|
||||||
|
// Validate required environment variables
|
||||||
|
if (!DB_PASSWORD) {
|
||||||
|
console.error('DB_PASSWORD environment variable is not set');
|
||||||
|
throw new Error('Database password is not configured');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct connection string from components
|
||||||
|
const connectionString = `postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}`;
|
||||||
|
|
||||||
|
// Log the connection string (with password masked for security)
|
||||||
|
const maskedConnectionString = connectionString.replace(/\/\/[^:]+:[^@]+@/, '//***:***@');
|
||||||
|
console.log('Using connection string:', maskedConnectionString);
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: process.env.NEWSDB_URL,
|
connectionString,
|
||||||
|
ssl: {
|
||||||
|
rejectUnauthorized: false // Required for some remote connections
|
||||||
|
},
|
||||||
|
// Add connection timeout
|
||||||
|
connectionTimeoutMillis: 5000,
|
||||||
|
// Add query timeout
|
||||||
|
query_timeout: 5000,
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
|
let client;
|
||||||
try {
|
try {
|
||||||
const client = await pool.connect();
|
console.log(`Attempting to connect to database at ${DB_HOST}:${DB_PORT}...`);
|
||||||
try {
|
client = await pool.connect();
|
||||||
const result = await client.query(
|
console.log('Database connection successful');
|
||||||
`SELECT id, title, date, source, description, category, url
|
|
||||||
FROM news
|
const result = await client.query(
|
||||||
ORDER BY date DESC
|
`SELECT id, title, date, source, description, category, url
|
||||||
LIMIT 5`
|
FROM news
|
||||||
);
|
ORDER BY date DESC
|
||||||
|
LIMIT 5`
|
||||||
return NextResponse.json(result.rows);
|
);
|
||||||
} finally {
|
|
||||||
client.release();
|
console.log(`Successfully fetched ${result.rows.length} news articles`);
|
||||||
}
|
return NextResponse.json(result.rows);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching news:', error);
|
console.error('Error in news API:', {
|
||||||
|
error: error instanceof Error ? error.message : 'Unknown error',
|
||||||
|
host: DB_HOST,
|
||||||
|
port: DB_PORT,
|
||||||
|
database: DB_NAME,
|
||||||
|
stack: error instanceof Error ? error.stack : undefined
|
||||||
|
});
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Failed to fetch news' },
|
{
|
||||||
|
error: 'Failed to fetch news',
|
||||||
|
details: error instanceof Error ? error.message : 'Unknown error',
|
||||||
|
server: DB_HOST
|
||||||
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
|
if (client) {
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user