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
|
||||
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
||||
LEANTIME_API_URL=https://agilite.slm-lab.net
|
||||
<<<<<<< HEAD
|
||||
|
||||
NEWSDB_URL=postgresql://alma:Sict33711###@cube.governance-labs.com/rivacube
|
||||
=======
|
||||
DB_USER=alma
|
||||
DB_PASSWORD=Sict33711###
|
||||
DB_NAME=rivacube
|
||||
# Database Configuration
|
||||
DB_HOST=cube.governance-labs.com
|
||||
>>>>>>> 1abc8e9fe8b5d9382da1c53238741114288da34c
|
||||
DB_PORT=5432
|
||||
DB_USER=alma
|
||||
DB_PASSWORD=Sict33711
|
||||
DB_NAME=rivacube
|
||||
|
||||
@ -1,14 +1,44 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
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({
|
||||
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() {
|
||||
let client;
|
||||
try {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
console.log(`Attempting to connect to database at ${DB_HOST}:${DB_PORT}...`);
|
||||
client = await pool.connect();
|
||||
console.log('Database connection successful');
|
||||
|
||||
const result = await client.query(
|
||||
`SELECT id, title, date, source, description, category, url
|
||||
FROM news
|
||||
@ -16,15 +46,27 @@ export async function GET() {
|
||||
LIMIT 5`
|
||||
);
|
||||
|
||||
console.log(`Successfully fetched ${result.rows.length} news articles`);
|
||||
return NextResponse.json(result.rows);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
} 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(
|
||||
{ error: 'Failed to fetch news' },
|
||||
{
|
||||
error: 'Failed to fetch news',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
server: DB_HOST
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
if (client) {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user