route.ts

src/app/api/post/route.ts
import { 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

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2026 Web Plant Media, LLC