I am trugguling really hard with making a simple POST request from production.
It works locally, it fails in production, I dont understand why.
This is my POST request:
export async function POST(request: Request){
console.log("calling post request!!!!")
const data = await req.json()
console.log("POSTING SOME DATA: ", data)
return NextResponse.json(data)
}
I am calling this request from api/email
the following way:
export async function simplePost(data: FormData, setEmailSent, setError) {
const apiEndpoint = '/api/email';
const res = await fetch(apiEndpoint, {
method: 'POST',
body: JSON.stringify(data),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
if(res.status === 200){
setEmailSent(true);
}else{
setError(true);
}
}
I am really frustrated, this is a simple, stupid post request, I can not understand why it doesnt work in production???
My folders look like this:
The error which I see on the console is page-198c25ba65ec6e90.js:1
POST https://my-website-on-production/api/email net::ERR_ABORTED 405 (Method Not Allowed)
I am in desperate need to make this work, please any help is highly appreciated!