folder support

This commit is contained in:
rattatwinko
2025-06-16 17:11:26 +02:00
parent 439d673e8f
commit 92fb64733b
5 changed files with 119 additions and 46 deletions

View File

@@ -37,12 +37,15 @@ async function getPostBySlug(slug: string) {
export async function GET(
request: Request,
{ params }: { params: { slug: string } }
{ params }: { params: { slug: string[] | string } }
) {
try {
const post = await getPostBySlug(params.slug);
// Support catch-all route: slug can be string or string[]
const slugArr = Array.isArray(params.slug) ? params.slug : [params.slug];
const slugPath = slugArr.join('/');
const post = await getPostBySlug(slugPath);
return NextResponse.json(post);
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch post' }, { status: 500 });
return NextResponse.json({ error: 'Fehler beim Laden des Beitrags' }, { status: 500 });
}
}