#POST request being converted to GET via binding

1 messages · Page 1 of 1 (latest)

brisk pendant
#

I have a website that I am migrating the api from a separate host to a single combined site using assets/spa with the path for the api being under "/api/"

In the handler, I have a very simple router:

const requester = async (env, url, headers, request) => { try { if (url.pathname.startsWith("/public/")) { console.log("Public route in requester", request.method, url.toString()); return await env.PUBLIC_ROUTER.fetch(url, { ...request }); } return await env.API_ROUTER.fetch(url, { ...request, headers }); } catch (e) { console.log("Something went wrong", JSON.stringify(e)); } };

If I send a POST request to: "/api/public/turnstile/" I get the following in the logs for the frontend router:

`2025-12-29 17:24:22:875 GMT
POST /api/public/turnstile/
Public route in requester POST https://api-router.*****/public/turnstile/

2025-12-29 17:24:22:865 GMT
POST /api/public/turnstile/
POST https://app-v3.******/api/public/turnstile/`

Which is what I am expecting....

However... in the public endpoint:

`2025-12-29 17:24:22:896 GMT
GET /public/turnstile/
This is the main handler for public routes 23

2025-12-29 17:24:22:878 GMT
GET /public/turnstile/
GET https://api-router.*****/public/turnstile/`

Which is what I would get if this was a GET request!

Any ideas?

hollow hound
#

How does the PUBLIC_ROUTER handle the request?

brisk pendant
#

Returns a 404 as there is no GET handler for that path.

If I hit the old api router, with the same path (less the /api/ at the beginning of the path) it works as expected

hollow hound
#

What does this console.log("Public route in requester", request.method, url.toString());
return?

#

If I understood correctly, you are sending a POST to /public/ but in PUBLIC_ROUTER it gets handled as a GET request?

brisk pendant
#

Hi Olaf -

It returns this: Public route in requester POST https://api-router.*****/public/turnstile/ - then the bound service receives it as a GET

brisk pendant
#

This gets more bizarre...

The headers is just headers = new Headers(request.headers)

If I replace the call with:

return await env.PUBLIC_ROUTER.fetch(url, { ...request, headers,});

Then no difference.

return await env.PUBLIC_ROUTER.fetch(url, { ...request, headers, method: request.method, });

The request gets through but there is no body!

return await env.PUBLIC_ROUTER.fetch(url, { ...request, headers, method: request.method, body: request.body });

This works!

hollow hound
#

Strange

warm whale
#

request is a class. … doesn’t behave as you’d expect