svrjs-nextjs-website/app/api/mods/route.ts

21 lines
618 B
TypeScript
Raw Normal View History

2024-06-22 10:30:51 +02:00
import { NextRequest, NextResponse } from "next/server";
import clientPromise from "@/lib/db";
// Force the API to use SSR instead of static generation
export const dynamic = "force-dynamic";
2024-06-22 10:30:51 +02:00
// Handler for GET requests
export async function GET(req: NextRequest) {
try {
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
2024-06-22 10:30:51 +02:00
const downloads = await db.collection("mods").find().toArray();
return NextResponse.json(downloads, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to fetch mods" },
{ status: 500 }
);
}
}