i am trying to make api (post)request through axios and giving the data to the api from frontend
but the backend is not etting data and its givng me axios error status 500
POST http://localhost:3000/api/generate-course-outline 500 (Internal Server Error)
here is my part in frontend from where i am making api call
const GenerateCourseOutline=async()=>{
const courseId=uuidv4();
// console.log("formData:", formData);
// console.log("createdBy:", user?.primaryEmailAddress?.emailAddress);
const result=await axios.post('/api/generate-course-outline',{
courseId:courseId,
...formData,
createdBy:user?.primaryEmailAddress?.emailAddress
})
console.log(result);
}```
this is where my api route is made
/api/generate-course-outline
```javascript
export async function POST(req) {
try {
const { courseId, topic, courseType, difficultyLevel, createdBy } = await req.json();
// generate course layout using ai
const PROMPT='Generate a study material for '+topic+' for '+courseType+' and level of difficulty will be '+difficultyLevel+'with the summary of course ,List of Chapters along with summary for each chapter,topic list in each chapter in JSON format '
const aiResp=await courseOutlineAIModel.sendMessage(PROMPT)
const aiResult=JSON.parse(aiResp.response.text());
// save the result along with user input
const dbResult=await db.insert(STUDY_MATERIAL_TABLE).values({
courseId:courseId,
courseType:courseType,
createdBy:createdBy,
topic:topic,
courseLayout:aiResult
}).returning({STUDY_MATERIAL_TABLE})
console.log(dbResult);
return NextResponse.json({ result: dbResult[0] })
} catch (error) {
console.error('Error in POST /api/generate-course-outline:', error);
return NextResponse.json({ error: 'An error occurred while processing your request' }, { status: 500 });
}
}
kindly help me fix tis