fix: use MongoDB database name from an environment variable

This commit is contained in:
Dorian Niemiec 2024-09-07 21:11:11 +02:00
parent 81950a1fc4
commit 44d84586ec
22 changed files with 27 additions and 26 deletions

View file

@ -1,4 +1,5 @@
MONGODB_URI=
MONGODB_DB=
UPLOADTHING_SECRET=
UPLOADTHING_APP_ID=

View file

@ -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")

View file

@ -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 };

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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")

View file

@ -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) });

View file

@ -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) });

View file

@ -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) });

View file

@ -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) });

View file

@ -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 });

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) },

View file

@ -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],

View file

@ -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,

View file

@ -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],

View file

@ -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,

View file

@ -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) {