logi
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 29s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 29s
This commit is contained in:
parent
39565dc522
commit
a2f053a54a
@ -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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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(/:\/\/([^:]+):([^@]+)@/, "://<username>:<password>@"));
|
||||
console.log(
|
||||
"[MongoDB] 📍 URI:",
|
||||
uri.replace(/:\/\/([^:]+):([^@]+)@/, "://<username>:<password>@"),
|
||||
);
|
||||
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<MongoClient>;
|
||||
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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user