9

is there a way that ApolloClient accepts request from servers with self signed certificates?

    import ApolloClient from 'apollo-boost';

    const client = new ApolloClient({
        uri: `https://${window.location.hostname}:8080/graphql`,
        rejectUnauthorized: false
    });
  • rejectUnauthorized: false doesn´t work

Error on a Request: OPTIONS https://localhost:8080/graphql net::ERR_CERT_AUTHORITY_INVALID

Marcel Rösler
  • 181
  • 3
  • 14

2 Answers2

3

Frontend

Apollo client might reject the certificate even if you clicked "I understand the risks" and went to the page. You can workaround this by enabling self signed certificates from local host: on chrome type

chrome://flags/#allow-insecure-localhost

to the navigation and click enable.

Other option is to install the certficate as trusted. More about that in this question.

Backend

If you are using Apollo client in backend with Nodejs you can start the process with:

NODE_TLS_REJECT_UNAUTHORIZED=0

This can be done with e.g. env-cmd package.

eemelipa
  • 1,180
  • 8
  • 11
  • doesn work. I've got the same problem https://stackoverflow.com/questions/75884056/vue-apollo-client-keeps-getting-self-signed-certificate-error?fbclid=IwAR3leAzS9QU8WboaxzxmYI_2LmBsHbM4VojLNPbOE7ZpN9l59v6YGOhH6Zk – nam vo Mar 30 '23 at 06:13
0

You can also use agent option for development:

let fetchOptions = {}

if (process.env.NODE_ENV !== 'production') {
  const https = require('https')
  fetchOptions = { agent: new https.Agent({ rejectUnauthorized: false }) }
}
const link = new HttpLink({
  uri: 'https://localhost/api/graphql',
  credentials: 'same-origin',
  fetchOptions,
})
ptim
  • 14,902
  • 10
  • 83
  • 103
ZiiMakc
  • 31,187
  • 24
  • 65
  • 105