Next.js Discord

Discord Forum

- error TypeError: Cannot read properties of undefined (reading 'headers')

Answered
Pacific herring posted this in #help-forum
Open in Discord
Pacific herringOP
I dont understand why I'm getting this error. Seems like it's happening in the POST function.

route.ts:
export async function POST(request: NextRequest) {
    console.log("post")
    const {type, severity, summary, explaination } = await request.json();

    addReport({type, severity, summary, explaination, author, assigned,);
}


page.tsx (using react hook form btw)
    const onSubmit: SubmitHandler<TNewBugForm> = async (data: any) => {

        const res = await fetch(`http://localhost:3000/api/bug/newbug`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }, body: JSON.stringify(data)
        });

        const result = await res.json();
        console.log(result.message);
Answered by joulev
return NextResponse.json({ message: "something" });
View full answer

6 Replies

Just to let you know, if it's local you don't need to use the http://localhost:3000 part, just the / then the path 🙂
return NextResponse.json({ message: "something" });
Answer
Thanks! This also resolved mine on a random page i created.
Pacific herringOP
Omg how the hell i didnt notice it
Pacific herringOP
forgot to mark as resolved