Looking to start a blog with Next.js 14 and I'm working on defining a function in api/posts/[postSlug]/route.js
. How do I access the postSlug
parameter within this function?
Here's my current function code:
// api/posts/[postSlug]/route.js
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
export async function GET (request) {
// const { postSlug } = params;
const postSlug = 'test'
console.log(request);
const post = await prisma.post.findUnique({
where: {
slug: postSlug
}
})
if (post)
return NextResponse.json({
post,
})
return NextResponse.json({
status: 'error',
message: 'not found!'
})
}