route.ts

src/app/api/posts/route.ts
import { NextRequest, NextResponse } from 'next/server'
import { filterPosts } from '@/utils/filter-posts'
export async function GET(req: NextRequest) {
const { searchParams } = req.nextUrl
const page = Math.max(1, Number(searchParams.get('page') || '1'))
const perPage = Math.min(
50,
Math.max(1, Number(searchParams.get('per_page') || '15'))
)
const params: Parameters<typeof filterPosts>[0] = { page, perPage }
const categorySlug = (searchParams.get('category') || '').trim()
if (categorySlug) params.categorySlug = categorySlug
const tagSlug = (searchParams.get('tag') || '').trim()
if (tagSlug) params.tagSlug = tagSlug
const authorSlug = (searchParams.get('author') || '').trim()
if (authorSlug) params.authorSlug = authorSlug
const exclude = (searchParams.get('exclude_categories') || '').trim()
if (exclude) params.categoriesExclude = exclude.split(',').filter(Boolean)

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