"405 Method Not Allowed for POST Requests in Vercel Production Environment". #68566
-
Link to the code that reproduces this issuehttps://github.com/VelankaniAIandCloudSolutions/VMS To Reproduce
Current vs. Expected behaviorSetup:
Issue Details:
2 ) 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 www.mydomain/api/invitations/create-visit.
Error Details: I've checked the Vercel logs and the network tab in the browser's developer tools; the error consistently shows as 500 & 405 in respective places, 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. Additional Information:
Screenshots: I'm really struggling to pinpoint the exact cause of this issue. It might be due to CORS configurations, an incorrect base URL, or something else entirely. I'm at a loss and would be extremely grateful for any help or suggestions to resolve this. I don't think the issue is due to CORS; it feels like something minor but hard to pinpoint. Provide environment informationOperating System:
Platform: linux
Arch: x64
Version: #127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024
Available memory (MB): 15867
Available CPU cores: 8
Binaries:
Node: 22.3.0
npm: 10.8.1
Yarn: 1.22.22
pnpm: 9.6.0
Relevant Packages:
next: 14.2.5 // Latest available version is detected (14.2.5).
eslint-config-next: 14.2.4
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)Not sure Which stage(s) are affected? (Select all that apply)Vercel (Deployed) Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
|
@Satvik-Katochh This CORS-related setup question is better suited for our Discussions! |
Beta Was this translation helpful? Give feedback.
-
|
I had the same issue where my API worked locally but returned 405 Method Not Allowed after deploying to Vercel. For me, the problem was Vercel Authentication (https://vercel.com/docs/security/deployment-protection) blocking unauthenticated requests. Fix: Go to your project in Vercel Dashboard. Navigate to Settings → General. Disable "Vercel Authentication". After disabling this setting, my API started working again! |
Beta Was this translation helpful? Give feedback.
-
|
Spend few hours in this issue, finally found a fix. Turns out my project is using static export Changed my config to /** @type {import('next').NextConfig} */
const nextConfig = {
// output: 'export', // Outputs a Single-Page Application (SPA).
// distDir: './dist', // Changes the build output directory to `./dist/`.
experimental: {
reactCompiler: true,
},
}
export default nextConfigNow working flawlessly |
Beta Was this translation helpful? Give feedback.
Spend few hours in this issue, finally found a fix.
Turns out my project is using static export
output: "export". This doenst support API: https://nextjs.org/docs/pages/guides/static-exports.Changed my config to
Now working flawlessly