refactor: modify layout to use ClientOnly and BackgroundBlobsClient components fix: correct import statement for ActivityFeed in the main page fix: enhance sitemap fetching logic with error handling and mock support refactor: convert BackgroundBlobs to default export for consistency refactor: simplify ErrorBoundary component and improve error handling UI chore: update framer-motion to version 12.24.10 in package.json and package-lock.json test: add minimal Prisma Client mock for testing purposes feat: create BackgroundBlobsClient for dynamic import of BackgroundBlobs feat: implement ClientOnly component to handle client-side rendering feat: add custom error handling components for better user experience
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
export const runtime = "nodejs"; // Force Node runtime
|
|
|
|
const GHOST_API_URL = process.env.GHOST_API_URL;
|
|
const GHOST_API_KEY = process.env.GHOST_API_KEY;
|
|
|
|
export async function GET(request: Request) {
|
|
const { searchParams } = new URL(request.url);
|
|
const slug = searchParams.get("slug");
|
|
|
|
if (!slug) {
|
|
return NextResponse.json({ error: "Slug is required" }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
// Debug: show whether fetch is present/mocked
|
|
// eslint-disable-next-line no-console
|
|
console.log('DEBUG fetch in fetchProject:', typeof (globalThis as any).fetch, 'globalIsMock:', !!(globalThis as any).fetch?._isMockFunction);
|
|
// Try global fetch first (as tests often mock it). If it fails or returns undefined,
|
|
// fall back to dynamically importing node-fetch.
|
|
let response: any;
|
|
|
|
if (typeof (globalThis as any).fetch === 'function') {
|
|
try {
|
|
response = await (globalThis as any).fetch(
|
|
`${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
|
|
);
|
|
} catch (e) {
|
|
response = undefined;
|
|
}
|
|
}
|
|
|
|
if (!response || typeof response.ok === 'undefined') {
|
|
try {
|
|
const mod = await import('node-fetch');
|
|
const nodeFetch = (mod as any).default ?? mod;
|
|
response = await nodeFetch(
|
|
`${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
|
|
);
|
|
} catch (err) {
|
|
response = undefined;
|
|
}
|
|
}
|
|
|
|
// Debug: inspect the response returned from the fetch
|
|
// eslint-disable-next-line no-console
|
|
console.log('DEBUG fetch response:', response);
|
|
|
|
if (!response || !response.ok) {
|
|
throw new Error(`Failed to fetch post: ${response?.statusText ?? 'no response'}`);
|
|
}
|
|
|
|
const post = await response.json();
|
|
return NextResponse.json(post);
|
|
} catch (error) {
|
|
console.error("Failed to fetch post from Ghost:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch project" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|