Apollo-client self signed certificate
Asked Answered
C

2

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

Cumulation answered 11/4, 2018 at 20:5 Comment(0)
M
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.

Masorete answered 30/10, 2019 at 11:56 Comment(1)
doesn work. I've got the same problem #75884556Lunsford
I
1

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,
})
Iolaiolande answered 25/2, 2021 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.