Apollo-client自签名证书

时间:2018-04-11 20:05:02

标签: javascript reactjs apollo apollo-client

有没有办法ApolloClient接受来自具有自签名证书的服务器的请求?

    import ApolloClient from 'apollo-boost';

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

请求错误: 选项https://localhost:8080/graphql net :: ERR_CERT_AUTHORITY_INVALID

2 个答案:

答案 0 :(得分:0)

解决此问题的一种简单方法是为您的过程设置环境变量:

NODE_TLS_REJECT_UNAUTHORIZED=0

答案 1 :(得分:0)

您也可以使用代理选项进行开发:

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,
})