405 Method Not Allowed on POST API in Vercel Production (Works Fine Locally)

Hey everyone,

I’m encountering an issue with my Next.js app where the POST API returns a “405 Method Not Allowed” error only in the Vercel production environment. Everything works perfectly fine locally, and I’m struggling to understand what’s causing this problem.

Setup:

  • Next.js Version: 14.2.4
  • Database: MySQL
  • Authentication & ORM: NextAuth.js & Sequelize
  • Deployment: Vercel

Issue Details:**

  • POST API Issue: Initially, both GET and POST methods were implemented in the same API for create-visit, but the GET method wasn’t working when POST was also present. After separating the GET logic into a different endpoint, the GET request works, but the POST request still returns a 405 error in production. The request is correctly made to mydomain/api/invitations/create-visit.
  • GET and PUT Issue: For the visitId API, both GET and PUT methods are defined for the same endpoint. Neither the GET nor the PUT request works in production—they both return a 405 error. Similar to the create-visit endpoint, if I separate the GET logic into a different endpoint, the GET request works, but the PUT request still doesn’t.

Error Details: I’ve checked the Vercel logs and the network tab in the browser’s developer tools; the error consistently shows as 405 Method Not Allowed, with no additional information to help diagnose the issue.

Environment Variables: I’ve double-checked that all environment variables are set correctly for both local and production environments.

Screenshots:

I’ve been stuck on this issue for a week now and would greatly appreciate any insights or suggestions. Thank you so much in advance for your help!

I’ve also added the cors policies in next.config.mjs, but still the same error is coming…also i’m able to signIn into the live site using inbuilt signIn from NextAuth.js, there is no CORS error encountered. So why no cors error is coming during signin? how’s that working?

Hi, @satvik-katochh!

Could you raise an issue in the Next.js repository?

Hi, @pawlean !!
Will do that, thanks!
Should I raise this as an issue or post this on discussion?

I’ve posted this as an issue, thanks
link to issue

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.