NeahFront7/app/api/news/route.ts
2025-04-14 00:36:39 +02:00

30 lines
625 B
TypeScript

import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
export async function GET() {
try {
const news = await prisma.news.findMany({
orderBy: {
date: 'desc'
},
take: 5,
select: {
id: true,
title: true,
date: true,
source: true,
description: true,
category: true,
url: true
}
});
return NextResponse.json(news);
} catch (error) {
console.error('Error fetching news:', error);
return NextResponse.json(
{ error: 'Failed to fetch news' },
{ status: 500 }
);
}
}