Apollo-link: How to avoid "self signed certificate" error?

Created on 10 Nov 2017  ·  12Comments  ·  Source: apollographql/apollo-link

import fetch from 'isomorphic-fetch';

const httpLink = new HttpLink({
  fetch,
  uri: `https://localhost:3000/graphql`,
});

Most helpful comment

For anyone wondering, you can also do:

const link = createHttpLink({
    fetchOptions: {
      agent: new https.Agent({ rejectUnauthorized: false }),
    },
})

All 12 comments

This used to be fix-able with agent: new https.Agent({ rejectUnauthorized: false }), given to a network interface. Now I don't know.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; did the thing for me.

For anyone wondering, you can also do:

const link = createHttpLink({
    fetchOptions: {
      agent: new https.Agent({ rejectUnauthorized: false }),
    },
})

@rtymchyk would you be able to add this to the docs? And what use case does this solve? I'm not familiar with agent?

@jbaxleyiii The use case it solves for me is connecting to my API node that has a self-signed SSL certificate on the dev environment. Requests from Apollo do not complete otherwise. I can add to docs if you think it's common enough.

I'm not sure its common enough but I could imagine people getting stuck on it and hard to find. I'd love to see it as a recipe if you are open to it!

@rtymchyk https module seems works only in NodeJs, How could it work in RN client?

When I try this on Android device (iOS device no problem), get the following error:

Error: While trying to resolve module https from file .../node_modules/https-agent/index.js, the package .../node_modules/https/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (.../node_modules/https/index.js. Indeed, none of these files exist:

Sorry, I'm not familiar with RN and what's available there.

With React Native you can't use https node module. Just speaking for myself the use case would be to test https connection in a react RN App locally, because iOS does not support anymore unsecured API calls.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; did the thing for me.

Where did you put it?

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; did the thing for me.

Where did you put it?

@pedzed add process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; in your you index.js file right after all the LaunchAPI & UserAPI constants. That should solve the problem.

Was this page helpful?
0 / 5 - 0 ratings