diff --git a/write-server/src/app/api/posts/route.ts b/write-server/src/app/api/posts/route.ts index 1f776d1b..1b21d587 100644 --- a/write-server/src/app/api/posts/route.ts +++ b/write-server/src/app/api/posts/route.ts @@ -1,9 +1,18 @@ import { NextRequest, NextResponse } from "next/server"; import { listPosts, createPost, getPostCount } from "@/lib/posts"; import { cleanExpired } from "@/lib/recycle"; +import { CONTENT_DIR, BLOG_ROOT } from "@/lib/config"; +import fs from "fs"; export async function GET(request: NextRequest) { try { + // Debug logging + console.log("[api/posts] BLOG_ROOT:", BLOG_ROOT); + console.log("[api/posts] CONTENT_DIR:", CONTENT_DIR); + console.log("[api/posts] cwd:", process.cwd()); + console.log("[api/posts] env BLOG_ROOT:", process.env.BLOG_ROOT); + console.log("[api/posts] CONTENT_DIR exists:", fs.existsSync(CONTENT_DIR)); + cleanExpired(); // housekeeping on each request const { searchParams } = request.nextUrl; @@ -15,8 +24,11 @@ export async function GET(request: NextRequest) { const result = listPosts({ search, page, perPage, includeDrafts }); const totalCount = getPostCount(); + console.log("[api/posts] result:", result.total, "posts"); + return NextResponse.json({ ...result, totalCount }); } catch (error: unknown) { + console.error("[api/posts] error:", error); return NextResponse.json( { error: error instanceof Error ? error.message : "Unknown error" }, { status: 500 }