Cloudflare Pages function onRequestPost results in 405 (Method Not Allowed)

For Workers & Pages, what is the name of the domain?

What is the error number?

405

What is the error message?

Method Not Allowed

What is the issue or error you’re encountering

onRequestPost is not triggered

What are the steps to reproduce the issue?

I use eleventy on Cloudflare pages with the following configuration:

  return {
    dir: {
      input: "src",
      output: "_site"
    }
  }

package.json commands are:

  "scripts": {
    "build": "npx @11ty/eleventy",
    "start": "npx @11ty/eleventy --serve",
    "debug": "DEBUG=* npx @11ty/eleventy"
  }

In wrangler.toml I specified:

pages_build_output_dir = "_site"

I added functions to the top directory of the project:

$ ls functions/*
functions/_middleware.js  functions/callback.js

From the deployment log I see that they are connected:

{
  "routes": [
    {
      "routePath": "/callback",
      "mountPath": "/",
      "method": "GET",
      "module": [
        "callback.js:onRequestGet"
      ]
    },
    {
      "routePath": "/callback",
      "mountPath": "/",
      "method": "OPTIONS",
      "module": [
        "callback.js:onRequestOptions"
      ]
    },
    {
      "routePath": "/callback",
      "mountPath": "/",
      "method": "POST",
      "module": [
        "callback.js:onRequestPost"
      ]
    },
    {
      "routePath": "/",
      "mountPath": "/",
      "method": "",
      "middleware": [
        "_middleware.js:onRequest"
      ]
    }
  ],
  "baseURL": "/"
}

GET and OPTIONS calls to /callback work as expected. However, POST request results to 405 error code which makes me think that onRequestPost is not even called. What could be the problem?