2024-06-20 20:46:05 +02:00
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
import clientPromise from "@/lib/db";
|
|
|
|
|
2024-06-22 11:57:32 +02:00
|
|
|
// Force the API to use SSR instead of static generation
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
2024-06-20 20:46:05 +02:00
|
|
|
// 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();
|
2024-06-22 11:23:31 +02:00
|
|
|
// console.log("Downloads fetched:", downloads);
|
2024-06-20 20:46:05 +02:00
|
|
|
return NextResponse.json(downloads, { status: 200 });
|
|
|
|
} catch (error) {
|
2024-06-22 10:30:51 +02:00
|
|
|
console.log(`Error Messge ${error}`);
|
2024-06-20 20:46:05 +02:00
|
|
|
return NextResponse.json(
|
|
|
|
{ error: "Failed to fetch downloads" },
|
|
|
|
{ status: 500 }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|