Skip to content
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

Support CloudFlare workers #217

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Support CloudFlare workers #217

merged 4 commits into from
Mar 12, 2024

Conversation

aron
Copy link
Contributor

@aron aron commented Mar 11, 2024

This PR adds support for CloudFlare worker environments. The main changes required were removing the use of the Buffer type in favor of it's underlying type TypedArray which is cross platform. And gating access to the process variable which is not available outside of Node.

The integration tests have been updated to successfully run the canary model against Replicate and verify the streamed results.

@aron aron force-pushed the cloudflare-support branch from 31f6a39 to d183c4c Compare March 11, 2024 11:59
@aron aron force-pushed the cloudflare-support branch from d183c4c to 327691f Compare March 11, 2024 12:00
Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

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

Great stuff. Thanks so much for this, @aron!

Very glad to see the -1,512 on this diff, by the way. Good use of npm workspaces.

@mattt mattt merged commit 742c664 into main Mar 12, 2024
12 checks passed
@mattt mattt deleted the cloudflare-support branch March 12, 2024 09:11
@mattt mattt mentioned this pull request Mar 12, 2024
aron added a commit that referenced this pull request Mar 12, 2024
This fixes a regression introduced with #214 where we were not exiting correctly when getting the `"done"` event from the server. This was picked up by the introduction of the CloudFlare integration tests added in #217 which uses the streaming API.

Once the fix was added it turns out that the `nock()` tests were incorrectly passing due to some internal weirdness when using `respondWith` and a `Readable` object. I wasn't able to get this working without hitting a different error:

    TypeError: Invalid state: Controller is already closed

It looks like nock is retaining some global state somewhere in it's implementation and streams are being retained across requests. No combination of resetting mocks seemed to fix it.

In the end I just mocked out the fetch function passed into the `createReadableStream` library and returned a `Response`. I think we should probably do this everywhere rather than use `nock()` as the Request/Response APIs provided by fetch are much better now than the old node http lib.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants