How do i send data from worker to durable object fetch?
Trying to do something along the lines of
but I keep getting 500 Internal Server Error when i try this. If i remove the "body" part from the fetch, it all works. I need to pass in data like this but I've been having trouble finding examples of this. Also the request is just the request I get from a worker, should that be there?
1 Reply
I'm pretty sure i need it, if i get rid of the {body: body} and make it just body my editor flags it because it needs to be a 'RequestInit<CfProperties<unknown>>'
I'm not getting any usefull error messages, just "500 Internal Server Error" when running wrangler dev locally and
when running wrangler dev remotely
Figured it out! I wrapped the fetch in a ctx.waitUntil() and for some reason that finally told me the error was because I was including a body in a GET http call. The line now just looks like
even though it doesn't really matter what the method is, the DO is really simple and only has one route
also in case anyone else is trying this I needed to include an application type header so the full line looks like this now
Ok final time posting here, I have now spent the last 48 hours trying to get this to work and it turns out things don't work well since the "upgrade": "websocket" header seems to only work with GET calls, and GET calls don't support bodys. The final solution I've come to is copying what the "itty-durable" library does and pass in the data through the header. my fetch now looks like this
I'm posting this in the small chance someone else comes across the same issue. TBH this experience has soured me a little bit on durable objects and the cloudflare worker environment but whatever its too late for me to switch now.