From a2f053a54a89e9ab6b8eb83f43cfac1c844b3b93 Mon Sep 17 00:00:00 2001 From: Adrian Miesikowski Date: Tue, 10 Feb 2026 20:58:08 +0100 Subject: [PATCH] logi --- app/api/blog/route.ts | 10 ++++++++-- lib/blog.ts | 6 ++++-- lib/mongodb.ts | 11 ++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/api/blog/route.ts b/app/api/blog/route.ts index 978a3eb..6ca49bc 100644 --- a/app/api/blog/route.ts +++ b/app/api/blog/route.ts @@ -7,7 +7,10 @@ export async function GET(request: Request) { console.log("[API] 🌐 GET /api/blog - Request received"); try { const { searchParams } = new URL(request.url); - const category = searchParams.get("category") as "case-study" | "blog" | null; + const category = searchParams.get("category") as + | "case-study" + | "blog" + | null; console.log("[API] 📋 Parameters:", { category }); const posts = await getAllPosts(category || undefined); @@ -20,6 +23,9 @@ export async function GET(request: Request) { }); } catch (error) { console.error("[API] ❌ Error:", error); - return NextResponse.json({ success: false, error: "Failed to fetch posts" }, { status: 500 }); + return NextResponse.json( + { success: false, error: "Failed to fetch posts" }, + { status: 500 }, + ); } } diff --git a/lib/blog.ts b/lib/blog.ts index e1eb166..a41c4be 100644 --- a/lib/blog.ts +++ b/lib/blog.ts @@ -63,7 +63,7 @@ export async function getAllPosts( const query = category ? { category } : {}; console.log("[Blog] 🔍 Query:", query); - + const posts = await db .collection(COLLECTION_NAME) .find(query) @@ -74,7 +74,9 @@ export async function getAllPosts( return posts.map(serializePost); } catch (error) { console.error("[Blog] ❌ Database Error:", error); - console.warn("[Blog] ⚠️ MongoDB connection failed, returning empty posts array"); + console.warn( + "[Blog] ⚠️ MongoDB connection failed, returning empty posts array", + ); return []; } } diff --git a/lib/mongodb.ts b/lib/mongodb.ts index 2d7dbb5..6b5e04a 100644 --- a/lib/mongodb.ts +++ b/lib/mongodb.ts @@ -1,11 +1,15 @@ import { MongoClient } from "mongodb"; // MongoDB connection from environment or fallback -const uri = process.env.MONGODB_URI || +const uri = + process.env.MONGODB_URI || "mongodb://mo1124_ai_web:~4nfR5EA)3%C2%A3%40@mongo76.mydevil.net:27017/mo1124_ai_web?authSource=mo1124_ai_web"; console.log("[MongoDB] 🔧 Initializing connection..."); -console.log("[MongoDB] 📍 URI:", uri.replace(/:\/\/([^:]+):([^@]+)@/, "://:@")); +console.log( + "[MongoDB] 📍 URI:", + uri.replace(/:\/\/([^:]+):([^@]+)@/, "://:@"), +); console.log("[MongoDB] 🌍 Environment:", process.env.NODE_ENV); // Use global variable to preserve connection across HMR in development @@ -18,7 +22,8 @@ let clientPromise: Promise; if (!globalWithMongo._mongoClientPromise) { console.log("[MongoDB] 🔌 Creating new connection..."); const client = new MongoClient(uri); - globalWithMongo._mongoClientPromise = client.connect() + globalWithMongo._mongoClientPromise = client + .connect() .then((client) => { console.log("[MongoDB] ✅ Connected successfully"); return client;