fix: support edge/serverless runtimes via axios adapter fallback (#31) - #107
Merged
Mantas97 merged 2 commits intoAug 5, 2026
Merged
Conversation
…lerlite#31) The SDK hard-failed in runtimes that don't ship Node's `http` module (Vercel Edge, Cloudflare Workers, Next.js edge routes, Deno) with `AxiosError: There is no suitable adapter to dispatch the request`. axios >= 1.7 can be given an ordered list of adapters and picks the first one supported by the current runtime. Passing `["http", "xhr", "fetch"]` keeps Node on `http` and browsers on `xhr` (no behaviour change), while edge/serverless runtimes that ship neither transparently fall back to the universal `fetch` adapter. Adds a self-contained unit test (mocks axios, no network) and documents edge support in the README. Fixes mailerlite#31 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbUHs855FyBt2J7cG2Qmhh
Mantas97
requested changes
Jul 27, 2026
Collaborator
There was a problem hiding this comment.
@CedricConday Clever solution for the problem 👍 Just one detail that needs to be addressed
`body` defaults to null, so `body && JSON.stringify(body)` passed `data: null` on bodyless calls. Node's http adapter tolerates that; workerd rejects a GET/HEAD Request carrying any body property, which broke every read call on Cloudflare Workers once the fetch adapter was in play. Adds a regression test that fails on the old form (expected undefined, received null) and one asserting bodies still serialize. Co-Authored-By: Claude <noreply@anthropic.com> Assisted-by: Claude Opus 5
Mantas97
approved these changes
Aug 5, 2026
Mantas97
left a comment
Collaborator
There was a problem hiding this comment.
Great 👏 Thanks for contributing!
tothambrus11
reviewed
Aug 5, 2026
| const passedConfig = axiosMock.mock.calls[0][0] as { adapter: unknown }; | ||
| // Ordering matters: Node/browser keep their existing adapter, while | ||
| // edge/serverless runtimes fall back to `fetch`. See issue #31. | ||
| expect(passedConfig.adapter).toEqual(["http", "xhr", "fetch"]); |
There was a problem hiding this comment.
This tests that the implementation has this particular array, but doesn't actually test the behavior. The correct test would be to create an integration test that uses the library from deno.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The SDK throws in runtimes that don't ship Node's
httpmodule — Vercel Edge Functions, Cloudflare Workers, Next.js edge routes, Deno — because axios can't find a usable adapter (reported in #31):Fix
axios ≥ 1.7 accepts an ordered list of adapters and selects the first one supported by the current runtime. All requests already funnel through a single
request()helper (src/utils/fetch.ts), so one change covers the whole SDK:http(no behaviour change; all recorded-tape tests stay green)xhrhttp/xhr) → transparently fall back to the universalfetchadapterNo new dependencies, no breaking changes, no major version needed.
axios@^1.15.0(already the declared dependency) ships thefetchadapter.Tests
src/utils/fetch.test.ts— a self-contained unit test (mocks axios, no network/API key) asserting the adapter fallback order.http).Docs
Added a short Edge & serverless runtimes note to the README.
Fixes #31
🤖 Generated with Claude Code
https://claude.ai/code/session_01DbUHs855FyBt2J7cG2Qmhh