Fix Axios adapter binding for Cloudflare Workers environment #257
+22
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Summary
What is this?
This PR addresses a critical issue where Typesense library users encounter "Illegal invocation" errors when using custom Axios adapters in Cloudflare Workers environment. The error occurs because the fetch adapter loses its
this
context when used in Workers. This implementation ensures proper binding of the adapter to the correct context, making the library usable on edge computing environments.Changes
Added Features:
ApiCall.ts
:getAdapter()
: A private method that intelligently handles Axios adapter configuration:undefined
when no adapter is configuredglobalThis
specifically in Workers environmentCode Changes:
ApiCall.ts
:AxiosAdapter
type for better type safetygetAdapter()
method inperformRequest
this
binding for the adapter in Workers contextContext
On issue #254 @isaacrowntree encountered that behavior on an edge runtime on Cloudflare Workers.
PR Checklist