database wf 7
This commit is contained in:
parent
e89574c7db
commit
75039435eb
2
.env
2
.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"
|
||||
|
||||
@ -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 }
|
||||
);
|
||||
}
|
||||
|
||||
@ -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 (
|
||||
<div className="text-center">
|
||||
<h1 className="text-4xl font-bold text-white mb-4">Bienvenue sur Enkun</h1>
|
||||
<p className="text-white/80 mb-8">Connectez-vous pour accéder à votre espace</p>
|
||||
<button
|
||||
onClick={() => signIn("keycloak", { callbackUrl: "/" })}
|
||||
onClick={() => signIn("keycloak", { callbackUrl })}
|
||||
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
||||
>
|
||||
Commit
|
||||
|
||||
@ -4,6 +4,7 @@ const envSchema = z.object({
|
||||
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
||||
DATABASE_URL: z.string().url(),
|
||||
NEWSDB_URL: z.string().regex(/^postgresql:\/\//, "Must be a valid PostgreSQL URL"),
|
||||
NEWS_API_URL: z.string().url(),
|
||||
KEYCLOAK_CLIENT_ID: z.string(),
|
||||
KEYCLOAK_CLIENT_SECRET: z.string(),
|
||||
KEYCLOAK_REALM: z.string(),
|
||||
|
||||
31
middleware.ts
Normal file
31
middleware.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { withAuth } from "next-auth/middleware";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export default withAuth(
|
||||
function middleware(req) {
|
||||
// Add custom middleware logic here if needed
|
||||
return NextResponse.next();
|
||||
},
|
||||
{
|
||||
callbacks: {
|
||||
authorized: ({ token }) => !!token,
|
||||
},
|
||||
pages: {
|
||||
signIn: "/signin",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except for the ones starting with:
|
||||
* - api/auth (auth endpoints)
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico (favicon file)
|
||||
* - public folder
|
||||
*/
|
||||
"/((?!api/auth|_next/static|_next/image|favicon.ico|public).*)",
|
||||
],
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user