Next.js Server Action - Error 405

I have deployed a Next.js (14.0.4) project using Pages.

In this project, there is a form that triggers a server action on submit. This server action is calling an external API with the form content, process the result and return a response to the app. This runs smoothly on local & Vercel, but wheen trying to do the same on Cloudflare pages, I get this error :

Failed to load resource: the server responded with a status of 405 ()

Did I misconfigured something ?

I’ve been struggling with this error! I hope you have found a workaround better than mine!

The error raised when you use server actions in static page. Server actions are just “HTTP POST” back to page so the 405 error is raised when posting to static page.
This was a bug on Next 13.x that fixed months ago, that’s why local & Vercel runs smoothly. Don’t know why not Cloudflare too!

My costly workaround was to turn those pages into edge runtime server pages, but quickly I ran into another problem that is: Pages functions script is over the 1MB size limit (workers.api.error.script_too_large)

Appreciate any hints/configuration/guidance for a better solution

Not sure if this will change in the future, but for me I had to add

export const runtime = 'edge'

to all pages in the /app directory that use Server Actions (or render components that use Server Actions).

1 Like

HTTP 405 is “method not allowed”, which means that the HTTP request method (like GET, POST, HEAD, PUT) isn’t accepted by the API end-point.

It may be related to this Bug: CF Captcha randomly changes file upload POST to GET in which a bug in Cloudflare causes the browser to randomly change a POST to a GET, which can easily result in a 405. Cloudflare did change it yesterday, but also introduced a related problem when sending POST requests.