TheKaiser
TheKaiser
CDCloudflare Developers
Created by TheKaiser on 8/31/2023 in #workers-help
How do i send data from worker to durable object fetch?
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
const ret = await roomDurable.fetch(request, {
headers: { ...request.headers.values(), "do-content": JSON.stringify(content), Upgrade: "websocket" },
});
const ret = await roomDurable.fetch(request, {
headers: { ...request.headers.values(), "do-content": JSON.stringify(content), Upgrade: "websocket" },
});
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.
6 replies
CDCloudflare Developers
Created by TheKaiser on 8/31/2023 in #workers-help
How do i send data from worker to durable object fetch?
also in case anyone else is trying this I needed to include an application type header so the full line looks like this now
return await roomDurable.fetch(request, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
return await roomDurable.fetch(request, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
6 replies
CDCloudflare Developers
Created by TheKaiser on 8/31/2023 in #workers-help
How do i send data from worker to durable object fetch?
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
return await roomDurable.fetch(request, { method: "POST", body: body });
return await roomDurable.fetch(request, { method: "POST", body: body });
even though it doesn't really matter what the method is, the DO is really simple and only has one route
6 replies
CDCloudflare Developers
Created by TheKaiser on 8/31/2023 in #workers-help
How do i send data from worker to durable object fetch?
I'm not getting any usefull error messages, just "500 Internal Server Error" when running wrangler dev locally and
/home/kai/Code/ez-chat/node_modules/wrangler/wrangler-dist/cli.js:30632
throw a;
^

Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read'
}

Node.js v20.5.1
/home/kai/Code/ez-chat/node_modules/wrangler/wrangler-dist/cli.js:30632
throw a;
^

Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read'
}

Node.js v20.5.1
when running wrangler dev remotely
6 replies
CDCloudflare Developers
Created by TheKaiser on 8/31/2023 in #workers-help
How do i send data from worker to durable object fetch?
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>>'
6 replies