logi
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 27s

This commit is contained in:
Adrian Miesikowski 2026-02-10 20:58:12 +01:00
parent 122d151182
commit b281672838
3 changed files with 17 additions and 6 deletions

View File

@ -7,7 +7,10 @@ export async function GET(request: Request) {
console.log("[API] 🌐 GET /api/blog - Request received"); console.log("[API] 🌐 GET /api/blog - Request received");
try { try {
const { searchParams } = new URL(request.url); 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 }); console.log("[API] 📋 Parameters:", { category });
const posts = await getAllPosts(category || undefined); const posts = await getAllPosts(category || undefined);
@ -20,6 +23,9 @@ export async function GET(request: Request) {
}); });
} catch (error) { } catch (error) {
console.error("[API] ❌ Error:", 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 },
);
} }
} }

View File

@ -63,7 +63,7 @@ export async function getAllPosts(
const query = category ? { category } : {}; const query = category ? { category } : {};
console.log("[Blog] 🔍 Query:", query); console.log("[Blog] 🔍 Query:", query);
const posts = await db const posts = await db
.collection<BlogPost>(COLLECTION_NAME) .collection<BlogPost>(COLLECTION_NAME)
.find(query) .find(query)

View File

@ -1,11 +1,15 @@
import { MongoClient } from "mongodb"; import { MongoClient } from "mongodb";
// MongoDB connection from environment or fallback // 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"; "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] 🔧 Initializing connection...");
console.log("[MongoDB] 📍 URI:", uri.replace(/:\/\/([^:]+):([^@]+)@/, "://<username>:<password>@")); console.log(
"[MongoDB] 📍 URI:",
uri.replace(/:\/\/([^:]+):([^@]+)@/, "://<username>:<password>@"),
);
console.log("[MongoDB] 🌍 Environment:", process.env.NODE_ENV); console.log("[MongoDB] 🌍 Environment:", process.env.NODE_ENV);
// Use global variable to preserve connection across HMR in development // Use global variable to preserve connection across HMR in development
@ -18,7 +22,8 @@ let clientPromise: Promise<MongoClient>;
if (!globalWithMongo._mongoClientPromise) { if (!globalWithMongo._mongoClientPromise) {
console.log("[MongoDB] 🔌 Creating new connection..."); console.log("[MongoDB] 🔌 Creating new connection...");
const client = new MongoClient(uri); const client = new MongoClient(uri);
globalWithMongo._mongoClientPromise = client.connect() globalWithMongo._mongoClientPromise = client
.connect()
.then((client) => { .then((client) => {
console.log("[MongoDB] ✅ Connected successfully"); console.log("[MongoDB] ✅ Connected successfully");
return client; return client;