Apollo-客户端自签名证书 [英] Apollo-client self signed certificate
问题描述
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
});
- rejectUnauthorized: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
转到导航并单击启用.
其他选项是将证书安装为受信任的.在这个问题中了解更多相关信息.
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屋!