fix: use MongoDB database name from an environment variable
This commit is contained in:
parent
81950a1fc4
commit
44d84586ec
22 changed files with 27 additions and 26 deletions
|
@ -1,4 +1,5 @@
|
|||
MONGODB_URI=
|
||||
MONGODB_DB=
|
||||
|
||||
UPLOADTHING_SECRET=
|
||||
UPLOADTHING_APP_ID=
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function generateMetadata({
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const fetchedPage = (await db
|
||||
.collection("pages")
|
||||
|
|
|
@ -19,7 +19,7 @@ const Page = async ({ params }: { params: { slug: string } }) => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const fetchedPage = (await db
|
||||
.collection("pages")
|
||||
|
@ -56,7 +56,7 @@ const Page = async ({ params }: { params: { slug: string } }) => {
|
|||
export async function generateStaticParams() {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const slugs = await db.collection("pages").find().toArray();
|
||||
return slugs.map((element) => {
|
||||
return { slug: element.slug };
|
||||
|
|
|
@ -25,7 +25,7 @@ const LogsPage: React.FC = async () => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
downloads = (await db
|
||||
.collection("logs")
|
||||
.find()
|
||||
|
|
|
@ -29,7 +29,7 @@ const DownloadPage: React.FC = async () => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
downloads = (await db
|
||||
.collection("downloads")
|
||||
.find()
|
||||
|
|
|
@ -29,7 +29,7 @@ const ModsPage: React.FC = async () => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
downloads = (await db
|
||||
.collection("mods")
|
||||
.find()
|
||||
|
|
|
@ -29,7 +29,7 @@ const Vulnerabilities = async () => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
downloads = (await db
|
||||
.collection("vulnerabilities")
|
||||
.find()
|
||||
|
@ -40,7 +40,7 @@ const Vulnerabilities = async () => {
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const pages = (await db
|
||||
.collection("pages")
|
||||
|
|
|
@ -12,7 +12,7 @@ export async function DELETE(
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const collection = db.collection("downloads");
|
||||
|
||||
const result = await collection.deleteOne({ _id: new ObjectId(id) });
|
||||
|
|
|
@ -12,7 +12,7 @@ export async function DELETE(
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const collection = db.collection("logs");
|
||||
|
||||
const result = await collection.deleteOne({ _id: new ObjectId(id) });
|
||||
|
|
|
@ -12,7 +12,7 @@ export async function DELETE(
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const collection = db.collection("mods");
|
||||
|
||||
const result = await collection.deleteOne({ _id: new ObjectId(id) });
|
||||
|
|
|
@ -15,7 +15,7 @@ export async function DELETE(
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const result = await db
|
||||
.collection("vulnerabilities")
|
||||
.deleteOne({ _id: new ObjectId(id) });
|
||||
|
|
|
@ -8,7 +8,7 @@ export const dynamic = "force-dynamic";
|
|||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const downloads = await db.collection("downloads").find().toArray();
|
||||
// console.log("Downloads fetched:", downloads);
|
||||
return NextResponse.json(downloads, { status: 200 });
|
||||
|
|
|
@ -8,7 +8,7 @@ export const dynamic = "force-dynamic";
|
|||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const downloads = await db.collection("logs").find().toArray();
|
||||
return NextResponse.json(downloads, { status: 200 });
|
||||
} catch (error) {
|
||||
|
|
|
@ -7,7 +7,7 @@ export const GET = async (
|
|||
{ params }: { params: { slug: string } }
|
||||
) => {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const { slug } = params;
|
||||
|
||||
if (!slug) {
|
||||
|
@ -28,7 +28,7 @@ export const PUT = async (
|
|||
{ params }: { params: { slug: string } }
|
||||
) => {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const { slug } = params;
|
||||
|
||||
if (!slug) {
|
||||
|
@ -80,7 +80,7 @@ export const DELETE = async (
|
|||
{ params }: { params: { slug: string } }
|
||||
) => {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const { slug } = params;
|
||||
|
||||
if (!slug) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
|||
|
||||
export const GET = async (req: NextRequest) => {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
try {
|
||||
const pages = await db.collection("pages").find().toArray();
|
||||
|
@ -20,7 +20,7 @@ export const GET = async (req: NextRequest) => {
|
|||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
const client = await clientPromise;
|
||||
const db = client.db();
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const { title, slug, content } = await req.json();
|
||||
|
||||
if (!slug) {
|
||||
|
|
|
@ -8,7 +8,7 @@ export const dynamic = "force-dynamic";
|
|||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const downloads = await db.collection("mods").find().toArray();
|
||||
return NextResponse.json(downloads, { status: 200 });
|
||||
} catch (error) {
|
||||
|
|
|
@ -15,7 +15,7 @@ export async function PUT(
|
|||
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const result = await db.collection("mods").updateOne(
|
||||
{ _id: new ObjectId(id) },
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function POST(request: Request) {
|
|||
const { fileName, version, downloadLink, fileSize } = body;
|
||||
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const result = await db.collection("downloads").insertOne({
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function POST(request: Request) {
|
|||
const { version, date, bullets } = body;
|
||||
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const result = await db.collection("logs").insertOne({
|
||||
version,
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function POST(request: Request) {
|
|||
const { fileName, version, downloadLink, fileSize } = body;
|
||||
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const result = await db.collection("mods").insertOne({
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function POST(request: Request) {
|
|||
const { version, date, bullets } = body;
|
||||
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
const result = await db.collection("vulnerabilities").insertOne({
|
||||
version,
|
||||
|
|
|
@ -8,7 +8,7 @@ export const dynamic = "force-dynamic";
|
|||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("downloadsDatabase");
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const downloads = await db.collection("vulnerabilities").find().toArray();
|
||||
return NextResponse.json(downloads, { status: 200 });
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in a new issue