route.ts•907 B
import { NextRequest, NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const url = searchParams.get('url');
if (!url) {
return NextResponse.json(
{ error: 'URL parameter is required' },
{ status: 400 }
);
}
// Get the article from the database
const db = getDb();
const article = db.prepare(`
SELECT * FROM articles WHERE url = ?
`).get(url);
if (!article) {
return NextResponse.json(
{ error: 'Article not found' },
{ status: 404 }
);
}
return NextResponse.json(article);
} catch (error) {
console.error('Error fetching article:', error);
return NextResponse.json(
{ error: 'Failed to fetch article' },
{ status: 500 }
);
}
}