Skip to content

fix(cloudflare): fix the node wrapper #661

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-parrots-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(cloudflare): fix the node wrapper
9 changes: 2 additions & 7 deletions packages/open-next/src/overrides/wrappers/cloudflare-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
const url = new URL(internalEvent.url);
(internalEvent.url as string) = url.href.slice(url.origin.length);

const { promise: promiseResponse, resolve: resolveResponse } =
Promise.withResolvers<Response>();

const streamCreator: StreamCreator = {
writeHeaders(prelude: {
statusCode: number;
Expand All @@ -52,17 +49,15 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
status: statusCode,
headers: responseHeaders,
});
resolveResponse(response);

return Writable.fromWeb(writable);
},
onWrite: () => {},
onFinish: (_length: number) => {},
};

ctx.waitUntil(handler(internalEvent, streamCreator));

return promiseResponse;
const internalResult = await handler(internalEvent, streamCreator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may fix it, but it also means that streaming will not work.
The handler in node returns only after the response is fully sent (and the streamCreator is not useful in this case)

Maybe using a custom Writable with a custom ReadableStream would help figure out what's the issue here (or resolving the response in onWrite (this may break other things, but at least it'll help figure out what's going on here)

return converter.convertTo(internalResult);
};

export default {
Expand Down
Loading