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

Unusable with CloudFlare workers due to Axios bug #395

Closed
sgammon opened this issue Apr 11, 2020 · 3 comments
Closed

Unusable with CloudFlare workers due to Axios bug #395

sgammon opened this issue Apr 11, 2020 · 3 comments

Comments

@sgammon
Copy link

sgammon commented Apr 11, 2020

Expected Behavior

I would expect to be able to use Contentful JS from a CloudFlare worker.

Actual Behavior

I cannot use Contentful's Node/JS SDK from a CloudFlare worker because of axios/axios#2507.

Possible Solution(s)

Steps to Reproduce

  1. Create a CloudFlare Worker.
  2. Install Contentful's JS SDK.
  3. Follow Contentful's directions to initialize the JS SDK.
  4. Observe that, even with minimal code (any code), the following error occurs:
var client = contentful.createClient({
  accessToken: config.accessToken,
  space: config.space
});

// ... later, in a function ...

const response = Contentful.client.getEntries({
    'content_type': 'SomeObject'
});

response.then((data) => {
  console.log('we got some simple data', data);
}, (err) => {
  console.error('we could not fetch some simple data', err);
});

Screen Shot 2020-04-11 at 2 08 26 AM

Context

This issue is blocking us from proceeding with Contentful.

Environment

  • Language Version: CloudFlare Worker
  • Package Version: 7.14.2
  • Which API are you using?: Delivery (but this issue will affect any network traffic from CFW)
@sgammon
Copy link
Author

sgammon commented Jul 24, 2020

hi contentful devs

people are pissed off about this

you've refused to fix it

we've stopped using your platform because of it

we even pushed code for you to try and fix this, but we just can't maintain it ourselves

there is no reason to use axios anymore when fetch is the norm and XHR is deprecated.

thanks,
a pissed off dev

@rande
Copy link

rande commented Aug 27, 2020

I have a quick code to make axios works on wrangler dev. This is very the first iteration, and a lot of features are missing, but this can can fire a request to Contentful API.

  return createClient({
    space: CONTENTFUL_SPACE_ID as string,
    accessToken: CONTENTFUL_DELIVERY_API as string,
    environment: CONTENTFUL_ENV || "master",
    adapter: async (config: AxiosRequestConfig) => {
      const url = new URL(`${config.baseURL}/${config.url}`);
      if (config.params) {
        for(const key of Object.keys(config.params)) {
          url.searchParams.append(key, config.params[key]);
        }
      }

      const request = new Request(url.href, {
        method: config.method ? config.method.toUpperCase() : "GET",
        body: config.data,
        redirect: 'manual',        
        headers: config.headers ? config.headers : {}
        // credentials: config.withCredentials ? 'include' : 'omit', // not implemented on CF
        //mode: 'cors' // not implemented on CF,
      });
      
      const response = await fetch(request);

      return {
        data: await response.json(),
        status: response.status,
        statusText: response.statusText,
        headers: response.headers,
        config: config,
        request: request
      };
    }
  });

@mayakarabula
Copy link
Member

closing the issue, if you still need help with this please reach out to Contentful support

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 a pull request may close this issue.

3 participants