src/app/api/post/route.tsimport { NextRequest, NextResponse } from 'next/server'export async function GET(request: NextRequest) {const slug = request.nextUrl.searchParams.get('slug')if (!slug) {return NextResponse.json({ error: 'Missing slug' }, { status: 400 })}const wpJson = (process.env.NEXT_PUBLIC_WORDPRESS_URL ? `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp-json` : undefined)if (!wpJson) {return NextResponse.json({ error: 'WordPress API not configured' }, { status: 500 })}const res = await fetch(`${wpJson}/wp/v2/posts?slug=${encodeURIComponent(slug)}`, {next: { revalidate: 300 },})if (!res.ok) {return NextResponse.json({ error: 'Failed to fetch post' }, { status: 502 })}
Showing the first 20 lines.
Get full code