svrjs-nextjs-website/app/api/downloads/route.ts
2024-06-21 00:16:05 +05:30

17 lines
527 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import clientPromise from "@/lib/db";
// Handler for GET requests
export async function GET(req: NextRequest) {
try {
const client = await clientPromise;
const db = client.db("downloadsDatabase");
const downloads = await db.collection("downloads").find().toArray();
return NextResponse.json(downloads, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to fetch downloads" },
{ status: 500 }
);
}
}