Skip to content

Cloudflare Workers support (by moving off of axios) #151

@drmercer

Description

@drmercer

Enhancement description

This SDK is currently unusable in Cloudflare Workers because it uses axios, which strangely doesn't support using fetch instead of the super-old XHR api (and it doesn't seem they plan to address it anytime soon axios/axios#1219). Moving from axios to something like isomorphic-fetch would solve the issue.

Bonus: doing this would make Deno work for free, I think, because Deno also supports fetch. (#19)

Alternative, easier solution: expose an options object for the TodoistApi constructor, with an adapter option that lets me pass a custom axios adapter to use.

The problem it solves

I can't use this Todoist SDK in Cloudflare workers currently. I get this error:

TypeError: adapter is not a function

This is caused by these lines in axios - it only supports node and environments with XHR. Cloudflare Workers is neither of those, unfortunately.

https://github.com/axios/axios/blob/65977f995c7b92aeca26aa1ba50e1d6678389002/lib/defaults/index.js#L22-L32

Alternatives

I haven't found a good workaround for this. One solution I've thought of is forking axios, gutting it and replacing the internals with fetch, and then using the resolutions/overrides field to make this package use my axios-but-actually-fetch package instead of the real axios. But that would be a lot of work 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions