import { eq } from "drizzle-orm"; import { apiJson } from "@/lib/api"; import { db, WebsiteArticles } from "@/lib/db"; /** * GET /api/articles/:slug — single website_article by slug, including the * fullStory body. Returns { error } (404) when the slug is unknown. */ export async function GET( _req: Request, { params }: { params: Promise<{ slug: string }> }, ) { const { slug } = await params; try { const [article] = await db .select({ id: WebsiteArticles.id, title: WebsiteArticles.title, slug: WebsiteArticles.slug, shortStory: WebsiteArticles.shortStory, fullStory: WebsiteArticles.fullStory, image: WebsiteArticles.image, createdAt: WebsiteArticles.createdAt, updatedAt: WebsiteArticles.updatedAt, }) .from(WebsiteArticles) .where(eq(WebsiteArticles.slug, slug)) .limit(1); if (!article) { return apiJson({ error: "Article not found" }, { status: 404 }); } return apiJson({ data: article }); } catch { // DB unavailable — treat as not found rather than a 500. return apiJson({ error: "Article not found" }, { status: 200 }); } }