-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?]: Cannot read request body in middleware or api route using cloudflare #1287
Comments
found a clue: |
I found out how to get the request body, so what I said about WritableStream may be irrelevant to this problem, but should probably be noted anyway. I was able to retrieve the body in CF Workers by reading it from export async function POST(event: CustomAPIEvent) {
const body = event.node.req.body.toString('utf8')
return new Response(body)
} In debugging and looking at the event object that cloudflare receives, I found 4 places that request/body occur: event.node.req.body
event.request.body
event.web.request.body
event.context.cloudflare.request.body
I believe the workers were throwing the hanging Promise error because the implementation of readBody was trying to read from a body that was already used in one of these 4 locations. This is probably all expected or obvious to maintainers, but just wanted to leave my findings here in case they help with developing SolidStart's API, because how I am doing it is probably just a stop gap and not the intended way. |
Thanks for reporting. Stuff like this shouldn't impact how we want to approach our API. This should be handled at the runtime level. I will tag this appropriately and forward it on. |
Question, does it work if you try to get it off the request. Like: const body = await event.request.text() The reason I ask is preferably we are pushing people towards that interface and it occurs to me that |
However... I pulled down the latest solid@latest and reran the test:
It seems it works locally on wrangler! |
wait there is no readBody in this version, I must have tested the wrong server, let me try again |
yeah .text() and .json() both seems to work, I guess this is the expected way to go now? |
I guess we can close this then. Please reopen if the issue persists with the latest solid-start and solid versions |
Duplicates
Latest version
Current behavior 😯
/routes/api/test.ts
Wrangler gives the error when trying to parse the body, as well as cloudflare when actually deployed
Expected behavior 🤔
give the parsed body and no error
Steps to reproduce 🕹
Steps:
Context 🔦
No response
Your environment 🌎
No response
The text was updated successfully, but these errors were encountered: