diff --git a/.env b/.env index 3a44c878..561d84f7 100644 --- a/.env +++ b/.env @@ -70,3 +70,5 @@ IMAP_USER=alma@governance-labs.org IMAP_PASSWORD=8s-hN8u37-IP#-y IMAP_HOST=mail.infomaniak.com IMAP_PORT=993 + +NEWS_API_URL="http://172.16.0.104:8000" diff --git a/app/api/news/route.ts b/app/api/news/route.ts index a5bc74d8..ec09ca53 100644 --- a/app/api/news/route.ts +++ b/app/api/news/route.ts @@ -1,7 +1,5 @@ import { NextResponse } from 'next/server'; - -// FastAPI server configuration -const API_URL = 'http://172.16.0.104:8000'; +import { env } from '@/lib/env'; // Helper function to clean HTML content function cleanHtmlContent(text: string): string { @@ -84,47 +82,41 @@ export async function GET() { try { console.log('Fetching news from FastAPI server...'); - const response = await fetch(`${API_URL}/news?limit=12`, { + const response = await fetch(`${env.NEWS_API_URL}/news?limit=12`, { method: 'GET', headers: { 'Accept': 'application/json', - } + }, + // Add timeout to prevent hanging + signal: AbortSignal.timeout(5000) }); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + console.error(`News API error: ${response.status} ${response.statusText}`); + return NextResponse.json( + { error: 'Failed to fetch news', status: response.status }, + { status: 502 } + ); } const articles = await response.json(); - const formattedNews: NewsItem[] = articles.map((article: any) => { - const { displayDate, timestamp } = formatDateTime(article.date); - return { - id: article.id, - title: truncateText(article.title, 100), // Increased length for better titles - description: article.description ? truncateText(article.description, 150) : null, // Increased length for better descriptions - displayDate, - timestamp, - source: formatSource(article.source), - category: formatCategory(article.category), - url: article.url || '#' - }; - }); + const formattedNews: NewsItem[] = articles.map((article: any) => ({ + id: article.id, + title: article.title, + displayDate: formatDateTime(article.date).displayDate, + timestamp: formatDateTime(article.date).timestamp, + source: formatSource(article.source), + description: truncateText(article.description || '', 200), + category: formatCategory(article.category), + url: article.url + })); - console.log(`Successfully fetched ${formattedNews.length} news articles`); return NextResponse.json(formattedNews); - } catch (error) { - console.error('API error:', { - error: error instanceof Error ? error.message : 'Unknown error', - server: API_URL - }); - + console.error('News API error:', error); return NextResponse.json( - { - error: 'Failed to fetch news', - details: error instanceof Error ? error.message : 'Unknown error' - }, + { error: 'Failed to fetch news', details: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ); } diff --git a/components/auth/signin-form.tsx b/components/auth/signin-form.tsx index 2ab0661f..0d7bc89f 100644 --- a/components/auth/signin-form.tsx +++ b/components/auth/signin-form.tsx @@ -1,14 +1,18 @@ "use client"; import { signIn } from "next-auth/react"; +import { useSearchParams } from "next/navigation"; export function SignInForm() { + const searchParams = useSearchParams(); + const callbackUrl = searchParams.get("callbackUrl") || "/"; + return (
Connectez-vous pour accéder à votre espace