Apollo客户端自签名证书 [英] Apollo-client self signed certificate

查看:96
本文介绍了Apollo客户端自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ApolloClient是否可以接受带有自签名证书的服务器的请求?

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

  • 拒绝未授权:false不起作用
  • 请求错误:选项 https://localhost:8080/graphql net :: ERR_CERT_AUTHORITY_INVALID

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

    推荐答案

    前端

    即使您单击我了解风险"并转到页面,Apollo客户端也可能拒绝该证书.您可以通过启用本地主机上的自签名证书来解决此问题:chrome类型

    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

    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.

    后端

    如果您在后端使用带有Nodejs的Apollo客户端,则可以使用以下方法启动该过程:

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

    NODE_TLS_REJECT_UNAUTHORIZED = 0

    这可以通过例如 env-cmd 包.

    这篇关于Apollo客户端自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆