Update route.ts
This commit is contained in:
1 parent
dc796c2b66
commit
4121a15587
1 file changed
+12
@@ -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 }
|
||||
|
||||
Reference in new issue
Block a user