CF Pages Functions Wrangler Dev 405 Method Not Allowed Locally

I’ve downloaded the sample form pages/function from git -

I haven’t made any changes and just tried to get it working via wrangler locally, but no matter what I try, when I POST via the submit button I get a 405 Method Not Allowed error.

I’ve tried creating my own very basic form with a function, but same 405 error everytime.

I’ve used Wrangler to test locally and publish to the CF pages service, same outcome

Have I missed something config-wise??

Appreciate any help.

This is the same issue I’m facing in production:
Page Function failing for POST requests - Developers / Cloudflare Pages - Cloudflare Community

I’ve seen your post also, kind of glad I’m not alone with this one…

Are you able to POST when running in wrangler dev??

Also for info - This is definitly limited to CF Pages as I can POST fine when running the same form in a CF Worker.

It sounds like to me that your Function isn’t actually running, and you’re hitting the asset server to fetch a static asset, which doesn’t accept POST requests so throws a 405.

Are you certain the function is running on the right URL, and the form is posting to that URL? Have you tried to wrangler pages tail with some logs? Or added another debug function on GET that echoes something back to verify your Functions are working as expected?

@cherryjimbo any GET request to a function code accepting GET work well.
But any POST request to a function accepting POST is not working.

Can you share a minimal way to reproduce this please?

@cherryjimbo I think you can just try the Github repo mentioned by @chris.myers.

Hey guys, this looks to be a really weird Cloudflare issue!
I just made a simple copy/paste of the code to a new Function in another path and it simply works.
But the same code in the older path still fails with 405.
And this occurs in both, localhost and production.
I don’t know what is going on, but if anyone else is running into this issue, just try to copy/paste your function to a new one in a new path.
Really weird!

Unable to reproduce:

$ curl -X POST
Function not something.html

$ cat functions/something.js
export function onRequest() {
  return new Response('Function not something.html');

$ curl -X POST

$ cat functions/post.js
export function onRequestPost() {
  return new Response('');

As @cherryjimbo mentioned, this error happens when your Function is not fired.

This would also confirm it isn’t firing your Function. Please provide a minimal reproducible example.

Hi Walshy,

I’ve just used your example and still get the 405:

I’ll post further info in separate replies as I can only embed one image…

Output of my directory structure:

This message is concerning, but you can see I have my functions in the correct location above??

Is there any issues with wrangler on Windows??

You’re running your command one directory up. You’ll want to go into “submittest”

Functions live at the root (where you run the command) but the root you want is in your project directory.

Thanks for that, great spot… This now works as expected.

For anyone else having this issue, only the static assets are deployed from the attribute e.g. wrangler pages dev and as Walshy advised the functions are only deployed from the root of the current directory your console/command window.

If you look at my previous screenshots, you will see I was in the parent directory, even though I was passing the full path to the attribute.

Thank to all who contributed.


I have a static website hosted with Pages and requesting some KV data through Pages Functions.
Every GET request to functions made with onRequestGet is working well, as expected.
But a POST request from a form submission to a function made with onRequestPost is failing with the HTTP status 405: Method not allowed.

Please, refer to: CF Pages Functions Wrangler Dev 405 Method Not Allowed Locally - Developers / Cloudflare Pages - Cloudflare Community

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